HTML and CSS Reference
this value down to the next lowest integer using the Math.floor() method, as shown in
the following expression:
The value of the hours variable will then be equal to 9 for the current date. You'll add
To calculate the hours left in the day:
1. Return to the clock.htm file and the NYClock() function in your text editor.
2. Below the statement that sets the value of the daysLeft field, insert the following
// calculate the hours left in the current day
var hours = (days - Math.floor(days))*24;
3. Change the statement that sets the value of the hrsLeft field to the following, as
shown in Figure 11-24:
// display hours rounded to the next lowest integer
document.clockform.hrsLeft.value = Math.floor(hours) + “ hour(s)”;
hours variable added to the nYclock() function
calculates the hours
left in the current day
rounds the hours value
down to the nearest integer
4. Save your changes to the file, and then reopen or refresh clock.htm in your Web
browser. The hrsLeft field displays the hours left in the current day as an integer.
See Figure 11-25.