HTML and CSS Reference
In-Depth Information
To revise the daysInMonth() function:
1. After the statement that declares the thisMonth variable, insert the following if
statement (see Figure 12-20):
Be sure to use the double
equal sign symbol (==)
and not the single equal
sign symbol (=) when
making a comparison in
an if statement.
// Revise the days in February for leap years
if (thisYear % 4 == 0) {
dayCount[1] = 29;
Figure 12-20
if statement for leap years
if the year is divisible by 4,
changes the number of
days in February to 29
2. Save your changes to the file.
Nesting if Statements
The above if statement works as a simple approximation, but it is not completely accurate.
In most cases, a year that is evenly divisible by 4 is a leap year. The only exceptions are
years that occur at the turn of the century, which are evenly divisible by 100. These years
are not leap years unless they are also evenly divisible by 400. Thus, years such as 1800,
1900, and 2100 are not leap years even though they are evenly divisible by 4. Years such
as 2000 and 2400 are leap years because they are evenly divisible by 400. Figure 12-21
shows the complete process used to determine whether a particular year is a leap year.
Figure 12-21
Process to calculate leap years
by 4?
not a leap year
by 100?
leap year
by 400?
not a leap year
leap year
Search WWH ::

Custom Search