EXERCISE 9.1: Enter the lucky.html text from Figure 9.2 into a new Web page, then load the page in the browser to verify that it behaves as described.Once you have done this, save a copy of the page under the name lotto.html and modify it so that it predicts the winner of a PICK-4 lottery. You should update the page's text appropriately and modify the button so that its label reads "Click for Today's PICK-4 Winner". The DisplayNumber function, instead of displaying a single number, should pick 4 random numbers from the range 0 to 9 and display them in an alert box, separated by dashes. Figure 9.4 depicts an example of an alert box containing a PICK-4 winning number.
![]()
Figure 9.4: Sample of a PICK-4 alert box.
Pick-4 Lotto Lucky Dave's Gift To You
Numbers rule our lives. If you would like the benefit of Lucky Dave's amazing powers of prognostication, click on the button below to receive today's Pick-4 Lotto winner!
EXERCISE 9.3: Enter the revised convert.html text from Figure 9.7 into a new Web page, then load the page in the browser to verify that it behaves as described.In EXERCISE 7.2 of Chapter 7, you expanded your temperature conversion page so that it could convert in both directions. Make similar modifications to the page in Figure 9.7, using text boxes for input and output. The page should include your FahrToCelsius and CelsiusToFahr functions, as well as two text boxes, one for Fahrenheit and one for Celsius. If users enter a temperature in the Fahrenheit box and click a button labeled "Fahr --> Celsius", then the corresponding temperature should appear in the Celsius box. Likewise, if they enter a temperature in the Celsius box and click the button labeled "Fahr <-- Celsius", the corresponding temperature should appear in the Fahrenheit box. Your page should look similar to the one depicted in Figure 9.9.
![]()
Figure 9.9: Sample of temperature conversion page.
Temperature Conversion Page Temperature Conversion Page
Enter a temperature in a box and click on the desired button to convert.
EXERCISE 9.5: Create a Web page named double.html that includes the DoubleIt function in the HEAD. The page should contain a text box with an initial value of 1 and a button labeled "Double It". When the user clicks the button, the DoubleIt function should be called to double the contents of the text box.If you start with a value of 1 in the text box, how many times must you click for the value to exceed 500? How many times to exceed 1000?
After 9 clicks, the number reaches 512. Double the Number
After 10 clicks, the number reaches 1,024.
EXERCISE 9.7: Reimplement your Magic 8-Ball page, magic.html, from Chapter 7 (EXERCISE 7.9). The page should contain a text area in which the user can enter a question, as well as a button to submit that question. When the user clicks the button, the program should generate a random response (as before) and display this response in a text box.Note: This page is unique in that it completely ignores the input it receives from the user. Of course, users may not realize this -- some may think that the Magic 8-Ball has considered their questions carefully before responding!
Magic 8-ball Magic 8-ball
Enter your question in the text area below:
EXERCISE 9.9: Create a Web page named newpics.html that is similar to pics.html, but which contains only one button controlling the image. When a user clicks this button, a function (with no inputs) should be called to randomly select among several images.For example, the following JavaScript statement, when executed, would randomly choose from among four image file names (happy.gif, sad.gif, scared.gif, and bored.gif) and assign the chosen file name to the SRC attribute of an image named face:
document.images.face.src = RandomOneOf(["happy.gif", "sad.gif", "scared.gif", "bored.gif"]);
Picture Fun How do you feel today?
![]()