0
   

Writing a function

 
 
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));
}
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,433 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Writing a function
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 12/26/2024 at 11:04:33