HTML and CSS Reference
In-Depth Information
EXPLANATION
3
Although we haven't formally covered if statements, we have used them in several
examples, and they should be easy to follow. (See Chapter 6, “Under Certain Con-
ditions,” for a formal introduction). If the value of temp is equal to 98.6 , then the
following block of statements will be executed.
4
If is the user entered 98.6, the alert box sends the message “ Your temp is normal
to the browser.
5
If line 3 is not true, the block of statements following else is executed. An alert box
will appear in the browser window saying, “ You are sick! ” (see Figure 5.26).
Figure 5.25 User enters a string. The parseFloat() function will convert it to a
floating-point number.
Figure 5.26 Output from Example 5.16.
5.3.3 The eval() Function
The eval() function evaluates a string as a JavaScript expression, returning the result of
the execution. 3 If there is no result, undefined is returned.
FORMAT
eval(String);
EXAMPLE
eval("(5+4) / 3");
3. The eval() function takes a primitive string as its argument, not a String object. If a String object is used, it
will be returned as is.
 
 
Search WWH ::




Custom Search