HTML and CSS Reference
In-Depth Information
To add the calcDays() function to the clock.htm file:
1. Return to the clock.htm file in your text editor.
2. Directly above the line that sets the value of the daysLeft field, insert the
following line:
var days = calcDays(today);
3. Change the line that sets the value of the daysLeft field to the following:
document.clockform.daysLeft.value = days + “ day(s)”;
Figure 11-18 highlights the revised code in the clock.htm file.
Figure 11-18
calling the calcdays() function
calculates the
number of days
until January 1st
displays the calculated days
4. Save your changes to the file.
5. Reload or refresh clock.htm in your Web browser. The daysLeft field at the top of
the page displays the calculated number of days until the New Year's Bash. See
Figure 11-19.
Figure 11-19
calculated days left value
the number of days
until January 1st
includes a fractional
part of a day
jbdphotography/Shutterstock.com
Trouble? If no value appears in the daysLeft field, you might have made an error
when entering the code. In your text editor, check the code in the calcDays()
function against the code shown in Figure 11-17, making corrections as needed.
Save the file and then repeat Step 5.
Search WWH ::




Custom Search