EXERCISE 7.1: Cut-and-paste the convert.html text into a new Web page and load this page into the browser to verify that it behaves as before.Once you have done this, modify the page so that it prompts the user for two temperatures, the low and high temperatures for the day. The page should display both temperatures as they were entered, as well as their Celsius equivalents.
New Improved Temperature Conversion
EXERCISE 7.3: Cut-and-paste the newmac.html text into a new HTML document and load this page in the browser to verify that it displays the four verses as described. Add code to the page so that it prints a fifth verse (use your favorite animal).
New Improved Old MacDonald
EXERCISE 7.5: Cut-and-paste the testmac.html text into a new HTML document and load this page in the browser to verify that it behaves as described. If you reversed the inputs in the first function call, i.e., OldMacVerse(sound, animal), would the browser be smart enough to recognize the mismatch? Why or why not?
Yes, the page behaves as described. The browser would not recognize the mismatch: parameters are always matched up with inputs by position, with the first parameter assigned the first input, the second parameter assigned the second input, and so on. The fact that similar variable names appear in the BODY and also in the function is irrelevant.
EXERCISE 7.7: Computer science often deals with extremes when it comes to time. Modern computers can perform billions of operations per second, and yet some tasks such as decoding an encrypted message still might require decades of computation.Create a Web page named years.html that will prompt the user for some number of years and display the corresponding time in seconds. To simplify this task, ignore leap years and assume that all years consist of exactly 365 days. For example, given an input value of 2.5, your page might display the following:
You entered 2.5 years. That's 78840000 seconds! Your page should include the definition of a function named yearsToSeconds that has one input, corresponding to a number of years, and returns the corresponding time in seconds. Feel free to use local variables to store temporary values in the computation. For example, you might first convert the number of years to days and store that value in a variable called numDays, then convert that value to hours, minutes, and finally seconds. Be sure to declare any variables that you use within the function.
Once you have your page working, use it to approximate how many seconds are left in this semester. In your college career? In your life? Report your results.
Years to Seconds
EXERCISE 7.9: An oracle is a person or entity that is able to reveal hidden knowledge or divine purpose. The Oracle at Delphi, for example, was a shrine where the ancient Greeks would go to ask the gods for guidance and advice. The modern day equivalent of the Oracle at Delphi is the Magic 8-ball (Tyco Toys, Inc.). The Magic 8-ball is an oversized billiard ball with a small window on its side. To receive its wisdom, you ask the Magic 8-ball a question, shake it vigorously, and then look at the response that appears in the window. Functionally speaking, the Magic 8-ball determines its answer by randomly selecting from a list of predetermined responses, such as "yes", "no", and "unclear - try again".Create a Web page named magic.html that simulates a magic 8-ball. It should prompt the user for a question, then use the RandomOneOf function to randomly select from a list of possible responses. Both the question and response should be displayed on the page. For example,
QUESTION: Will the Cubs win the world series in my lifetime? ANSWER: highly unlikely Test your page to make sure that it does indeed provide different answers each time it is loaded.
Magic 8-Ball