(Last Updated 11/19/98)



Java Script Y2K Countdown



The Y2K window that came up with this page is an example of how simple coding can be used to change a simple alert panel into an interesting part of a page. It is activated in ressponse to the page load {onload="Y2Kalert()"}. In addition to calculating the number of days left before Jan 1, 2000, the code randomly chooses one of five messages to display. This code was taken intact from my Y2K dicussion page.

I very rarely affix a copyright header to scripts but I have to this one. The script is freeware and may be used by anyone as long as the header remains intact with the code.

The code that produced the alert is:
<SCRIPT LANGUAGE="Javascript">

//----------------------- Y2K Countdown script -----------------------------
// Y2K Countdown Script by; C Paulson of
// Cognitive Portals
// https://members.tripod.com/~SleepyCP/Cognit.html
// cpaulson@home.com
// The script is freeware but please keep the header intact.
//--------------------------------------------------------------------------

var y = 10*Math.random();
var z = Math.floor(y);
var w = z - 5*(Math.floor(z/5.0));
function Y2Kalert() { var today = new Date();
var day = today.getDate(); // day of the month {1-31}
var month = today.getMonth(); // present month {0-11}
var year = today.getYear(); // present year {0-99}
var hour = today.getHours(); // present hour {0-23}
var minute = today.getMinutes(); // present minute {0-59}
var second = today.getSeconds(); // present second {0-59}

// Date.UTC - date & time in Greenwich Mean (Universal) Time
// returns # of millisecondsfrom Jan 1, 1970 00:00:00
// arguments: year, month, day, hours, Min, sec

var Y2k = Date.UTC(99,11,31,23,59,59) + 1000;
var Now = Date.UTC(year,month,day,hour,minute,second);
var x = Math.floor((Y2k - Now)/(24*60*60*1000));

var int1 = "are ";
var int2 = " days";
if (x < 10 ) { int1 = " is ";
int2 = " day ";
} else { int1 = "are "; }

w++;
if (w == 6) w = 1;

var message = "default";
//
//--------------------------------------------------------------------------
// The following code only works with Netscape and IE 4
// Its a more elegant codeing so it will be retained for the future
// however coding suitable for version 3 will be used for now
// There is no point checking the version since V3 code works on both.
//
// switch(w) {
// case 1:
// message=" The sky is falling!!!";
// break;
// case 2:
// message=" I'm late! I'm late!\n I'm late, I'm late, I'm late.\n No time to say hello, goodbye....";
// break;
// case 3:
// message=" (Dum-De-Dum-Dum)";
// break;
// case 4:
// message=" Let the games begin.";
// break;
// case 5:
// message=" Y2K can't affec t m e e e\n e e e e !!";
// break;
// }
//------------------------------ Version 3 Code ---------------------------- if (w == 1) message=" The sky is falling!!!";
if (w == 2) message=" I'm late! I'm late!\n I'm late, I'm late, I'm late.\n No time to say hello, goodbye....";
if (w == 3) message=" (Dum-De-Dum-Dum)";
if (w == 4) message=" Let the games begin.";
if (w == 5) message=" Y2K can't affec t m e e e\n e e e e !!";
//--------------------------------------------------------------------------
if (x > 0) { alert("\n"+" Yikes!! There "+int1+x+int2+" left \n" +" before\n"
+" Year 2000!!!\n"+"\n"+message);
}
}

</SCRIPT>

I believe the code is relatively self documented so I woun't belabor it by repeating all the documentation here.



Contact Carl Paulson with questions,
or Visit my pages.