HTML and CSS Reference
In-Depth Information
Exercises
1. In the expression 6 + 4 / 2 % 2 what are the operands and in what order are they
evaluated? Show operator preference by using parentheses.
2. How can JavaScript tell if the + is used for concatenation or addition? Write a
short program to demonstrate.
3. a. If x is assigned the value of 5 , what is y in the following two statements:
y = --x;
y = x--;
b. Explain the output of the preceding two statements.
4. a. Are the following true or false?
22 == "22"
22 === "22"
"2" > "100"
b. Write a script to prove your answers to the preceding. In the same script, use
the following two statements:
document.write("3" + "4");
document.write(3 + 4);
c. Explain the output of the two preceding statements.
5. Example 5.8 prompts the user for his or her age. The user's response is assigned
to the variable answer as a string value. Rewrite the program to assure that the
age entered is a number before testing it. How do you do this?
6. Ask the user for a Fahrenheit temperature, and then convert it to Celsius. Use
parseFloat() . To specify the precision of the number, see “The Number Object”
on page 259 in Chapter 9. Formula for conversion: C = 5/9(F - 32).
7. The user is visiting Thailand. He or she has 65 U.S. dollars. Tell the user how
many Thai baht that amounts to. Display an image of the Thai flag on the same
page.
Search WWH ::




Custom Search