HTML and CSS Reference
In-Depth Information
condition
statement
executed if
condition is True
condition
statement
executed if
condition is True
JavaScript code
Figure 10-8
If the current value of the beginPos variable exceeds the length of the adMsg variable,
the statement assigns the value zero to the beginPos variable. By setting beginPos to zero,
the JavaScript code starts over assigning the first character of the string message to the text
field, which gives the illusion the text is scrolling in the text field.
To Enter an if Statement
Table 10-6 shows the code to enter an if statement.
Table 10-6 Code to Enter an if Statement
Line
Code
13
if (beginPos>adMsg.length) {
14
beginPos=0
15
}
The following step enters an if statement.
1
If necessary, click line 13
and indent under the
previous line.
Enter the code in
if statement tests if character
position has exceeded length
of message
Table 10-6, indenting
as shown, to add
the if statement
to test the
beginPos value, and
press the e n t e r key
(Figure 10-9).
Do all JavaScript if
statements have to be
written in this format?
When only one statement follows the condition, like in this example, the statement could have
been written as follows: if (beginPos>adMsg.length) beginPos=0 . Note that the braces
have been dropped for just one statement to be executed if the condition is true. If more than one
statement needs to be executed, then the braces must be used to create the block of statements.
insertion
point
if all characters in message
have been used, then start
over from beginning character
Figure 10-9
Search WWH ::




Custom Search