HTML and CSS Reference
In-Depth Information
Putting all of these commands together, the complete calcDays() function is:
function calcDays(currentDate) {
// create a Date object for January 1 of the next year
newYear = new Date(“January 1, 2015”);
nextYear = currentDate.getFullYear()+1;
newYear.setFullYear(nextYear);
// calculate the difference between currentDate and January 1
days = (newYear - currentDate)/(1000*60*60*24);
return days;
}
You'll add these commands and comments to the calcDays() function.
To revise the calcDays() function:
1. Below the first comment line in the calcDays() function, add the following lines:
newYear = new Date(“January 1, 2015”);
nextYear = currentDate.getFullYear()+1;
newYear.setFullYear(nextYear);
2. Below the next comment line, add the following line:
days = (newYear - currentDate)/(1000*60*60*24);
3. Complete the function by adding the following command to return the value of
the days variable:
return days;
Figure 11-17 shows the revised code in the calcDays() function.
Figure 11-17
adding commands to the calcdays() function
4. Save your changes to the file.
You can use the calcDays() function to calculate the number of days remaining in
the year, displaying that value in the daysLeft field of the Web form on the New Year's
Bash Web page. You'll add this function to the clock.htm file, replacing the placeholder
value of 99 that you specified earlier for the number of days remaining in the year.
 
Search WWH ::




Custom Search