HTML and CSS Reference
In-Depth Information
Figure 12-16
calling the writeDaynames() function
4. Save your changes to the file.
5. Reopen or refresh ccc.htm in your Web browser. The monthly calendar displays a
second row containing the abbreviations of the seven days of the week. See
Figure 12-17.
Figure 12-17
row of weekday abbreviations
created using the
writeDayNa m es() function
Exploring the while Loop
The for loop is only one way of creating a program loop in JavaScript. Before continu-
ing with the calendar() function, you'll investigate a few others. Similar to the for loop is
the while loop , in which a command block is run as long as a specific condition is met.
Unlike the for loop, the condition in a while loop does not depend on the value of a
counter variable. The while loop has the general syntax
while ( continue ) {
where continue is a Boolean expression that must be true for the command block to
be run; otherwise, the command block is skipped and the program loop ends.
The following code shows how to create the table shown in Figure 12-12 as a
while loop:
var i = 0;
while (i < 4) {
document.write(“<td>” + i + “</td>”);
Search WWH ::

Custom Search