Reply
Sat 4 Jun, 2011 02:53 pm
How do I answer this question: (I've been struggling for days with this!)
Insert a function named countdown(). The function has no parameters, but should include commands to write the following HTML code to the Web document:
Today is: <br />
date
<br /><br /> There are:
days
days until Thanksgiving
where "date" is the text returned by the showDate function and "days" is the text returned by the daysToThanksgiving function. Neither function requires a parameter value. (The code for the showDate and daysToThanksgiving functions are below:)
function showDate() {
thisDate = new Date();
var thisWDay=thisDate.getDay();
var thisDay=thisDate.getDate();
var thisMonth=thisDate.getMonth();
var thisYear=thisDate.getFullYear();
var mName = new Array("January", "February", "March", "April", "May",
"June", "July", "August", "September", "October","November", "December");
var wdName = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
return wdName[thisWDay]+", "+mName[thisMonth]+" "+thisDay+", "+thisYear;
}
function daysToThanksgiving() {
var thisDate = new Date();
var year = thisDate.getFullYear();
var tday = calcThanksgiving(year);
var tdate = new Date("November "+tday+", "+year);
if (thisDate > tdate) {
year++;
tday = calcThanksgiving(year);
tdate = new Date("November "+tday+", "+year);
}
return Math.floor((tdate-thisDate)/(1000*60*60*24));
}