EXERCISE 4.1: Cut-and-paste the greet.html text into a new Web page and verify that it behaves as described. In particular, what is displayed if the user clicks OK without entering a value in the input area?
The page behaves as described. If the user does not enter a name, the default value (the empty string) will be used, resulting in the message "Hello , welcome to my Web page."
EXERCISE 4.3: Each of the following is invalid as a JavaScript variable name. Explain why.
2hotforU salary$ two words "sum_to_date" name
2hotforU does not start with a letter
salary$ contains an illegal character, '$'
two words contains an illegal character, a space
"sum_to_date" has quotes around it, making it a string
name is a reserved word
EXERCISE 4.5: Cut-and-paste the food.html text into a new Web page and verify that it behaves as described. In particular, what is displayed if the user clicks OK without entering values at the prompts?
The page behaves as described. If the user does not enter a food at the prompts, the default value "chocolate" will be displayed as their favorite food, while the default value "brussels sprouts" will be displayed as their least favorite food.
EXERCISE 4.7: Cut-and-paste the oldmac.html text into a new Web page and verify that it behaves as described.
The page behaves as described.
EXERCISE 4.9: Modify your oldMac.html page so that it stores the refrain in a variable and then uses that variable in the write statements. That is, add the assignmentrefrain = "E-I-E-I-O"; at the very top of the JavaScript code (just after the opening SCRIPT tag) and modify the write statements as in the following:document.write(" Since the spelling assigned to the refrain variable is the same as before, the behavior of the page should not change.Old MacDonald had a farm, " + refrain + ".
");
Old MacDonald Old MacDonald had a Farm
EXERCISE 4.11: Create a Web page named madlib.html that serves as an interactive Mad Lib program. Your page should contain JavaScript code that prompts the user for words to fill in the blanks in a story, and then stores those words in variables. After having read in all of the words, your code should then display the story in the Web page, using the values of the variables where appropriate.The content of the story can be anything that you like -- be creative! Your story must meet the following conditions, however.
- It must be at least two paragraphs long.
- It must have at least six missing words.
- At least one of the missing words must be used multiple times in the story. For example, the person's name was used twice in the sample story above.
- The page should have a title, centered at the top, that includes your name.
Dave's Mad Lib