<html>
<head>
<title>Christmas tracker</title>
</head>
<body bgcolor="#000000" text="#FFFFEE" link="#0D03B8">
lt;p><font size = "+1">Attention K-Mart shoppers,
<script language="JavaScript">
<!--
// Create two date objects, today and Xmas, to hold today's date and Xmas date
// Analysis
var today = new Date();
var Xmas = new Date();
var diff, daysToXmas, weeksToXmas;
// Set Xmas' month and day properties to Christmas
// Note: Subtract one from month (0 = Jan, 1 = Feb, etc.)
// Analysis
Xmas.setMonth(11);
Xmas.setDate(25);
// Convert today and Xmas to the number of milliseconds since Jan 1 1970
// and then subtract the two numbers
// Analysis
diff = Xmas.getTime() - today.getTime();
// If Xmas falls later in the year (positive), convert from milliseconds to days,
// else convert to days and add 365 to get number of days until NEXT Christmas
// Analysis
if(diff >= 0)
daysToXmas=(((diff/1000)/60)/60)/24;
else
daysToXmas=(365 + (((diff/1000)/60)/60)/24);
// Divide by 7 to get weeks until Xmas, use modulus to get remaining days
// Use floor() to round down to even numbers
// Analysis
weeksToXmas = Math.floor(daysToXmas / 7);
daysToXmas = Math.floor(daysToXmas % 7);
// Print (semi-)gramatically correct message
// Analysis
if(weeksToXmas == 1)
document.writeln(' there is 1 week and ');
else
document.writeln(' there are ' + weeksToXmas + ' weeks ');
if(daysToXmas == 1)
document.writeln(' and 1 day ');
else
document.writeln('and ' + daysToXmas + ' days ');
document.write('left until Christmas. Ho! Ho! Ho!</font>');
if(weeksToXmas == 0 && daysToXmas ==0)
document.writeln('</font><font size = "7"><p>Have you been naughty or nice?');
// End Script -->
</script>
</font><p>send gifts to:
<p>Travis Simon<br>c/- Australian Personal Computer Magazine
<br>Level 8, 54 Park Street<br>Sydney NSW 2000
</body>
</html>
Back to example page or execute code