Last Exam is Over

Friday, 20 June 2008 21:43 by frimbob

blog_200608Well  have finished my last exam , on Tuesday. It was for my XML for web-applications, class I must admit I am glad that was the last exam, now I get to work on some personal projects. How did I do? Well after some exam nerves I made a good recovery and think a credit mark deserving for that paper.

So Now What?

Well I have made a start by completing my wow memorial page, I added a JavaScript clock to count up the number of days 'World of WarCraft' free.

The Script

   1: //namespace declaration
   2: var CountUp = function ()
   3: { } //end of name space
   4:  
   5: // Class Declaration
   6: CountUp.Class = function () {
   7:     //private references
   8:     var currentTime=new Date()
   9:     var startingdate;
  10:     var timesup=false
  11:     var baseunit;
  12:     var result;
  13:     //private method:
  14:     var PrintResults = function(){
  15:         var strresults = " ";
  16:         //Display the result             
  17:         strresults += '<div style="width:300px; background-color:#383838; text-align:center; color:white; margin-bottom:15px; margin-top:5px;">'
  18:         strresults += '<div style="width:300px; font-size:120%; text-align:center; background-color: #5E3A3A; color:white;"> Number of Days Without WOW </div>'; //opend
  19:         strresults += result.days + ' :Days ';
  20:         strresults += result.hours +' :Hours ' ;
  21:         strresults += result.minutes + ' :Minutes ';
  22:         strresults += result.seconds + ' :Seconds ';
  23:         strresults += "</div>" //close 
  24:         document.getElementById("ClockDiv").innerHTML = strresults;         
  25:     } //end function 
  26:     return  { //the returned object here 
  27:         //public declarations (declare as below)
  28:         ExampleProperty: 1, // note need comma after 
  29:                 
  30:         //init function
  31:         init: function (time,baseunit) {
  32:             startingdate=new Date(time)
  33:             baseunit=baseunit
  34:         //Add call Function to the SetInterval 
  35:         setInterval(CountUp.Class.showTime,3000); 
  36:         //accessing private variable
  37:         //abc ="jfk"
  38:         },
  39:        //Public Functio
  40:         showTime:  function() {
  41:             currentTime.setSeconds(currentTime.getSeconds()+1);
  42:             var timediff=(currentTime - startingdate) /1000; //difference btw target date and current date, in seconds
  43:             var oneMinute=60; //minute unit in seconds
  44:             var oneHour=60*60; //hour unit in seconds
  45:             var oneDay=60*60*24; //day unit in seconds
  46:             var dayfield=Math.floor(timediff/oneDay);
  47:             var hourfield=Math.floor((timediff-dayfield*oneDay)/oneHour);
  48:             var minutefield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour)/oneMinute);
  49:             var secondfield=Math.floor((timediff-dayfield*oneDay-hourfield*oneHour-minutefield*oneMinute));
  50:             if (baseunit=="hours"){ //if base unit is hours, set "hourfield" to be topmost level
  51:                 hourfield=dayfield*24+hourfield;
  52:                 dayfield="n/a";
  53:             }
  54:             else if (baseunit=="minutes"){ //if base unit is minutes, set "minutefield" to be topmost level
  55:                 minutefield=dayfield*24*60+hourfield*60+minutefield;
  56:                 dayfield=hourfield="n/a";
  57:             }
  58:             else if (baseunit=="seconds"){ //if base unit is seconds, set "secondfield" to be topmost level
  59:                 var secondfield=timediff;
  60:                 dayfield=hourfield=minutefield="n/a";
  61:             }
  62:             result={days: dayfield, hours:hourfield, minutes:minutefield, seconds:secondfield};
  63:             // call print method
  64:             PrintResults();  
  65:         } //, (remove comment syntax if more than one function)
  66:         
  67:     };
  68: }(); // the parens here cause the anonymous function to execute and return
  69:  
  70: //initilize the object
  71: CountUp.Class.init("January 5,2008, 17:15:00","days"); 

It was not very difficult I used the YUI pattern that I posted about a few months ago, as the base with the int method registering the time function with a setInterval() at repeat of 1 seconds or so.  The time function finds the difference from the base date compared to now then builds a result object and calls a print method.

Also to note that I used the script found on dynamic drive here, as the base for the Set-time function, I basically re-coded for the YUI pattern and wrote my own display method. 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading