The relevant files for this homework assignment are available in the CS 10 class folder under Homework/HW8, or as a downloadable .zip file here.
Create a Web page called Swapper.html that looks like the page shown below. After the user enters values in Field A and Field B, clicking the Swap Values button should cause the values shown in the fields to be swapped.
You can then use these two functions in your main program to generate the HTML code for the daily special, based on the current weekday. To find out the weekday, just use a Date object. Your main program code should go between the <script> tags appearing after the <h4>Today's Special</h4> heading. Don't forget to include <dl>, <dt>, and <dd> tags to format the daily special appropriately. To reduce the amount of typing, you can cut-and-paste the names and descriptions of the daily specials from the file menutext.txt.
For testing purposes, you may want to create Date objects for particular fixed dates (as opposed to the actual current date), so that you can be sure your program works for each day of the week.
Case Problem 2 (Madison State College) on page 8.46. The relevant files are in the Twain subfolder. This problem is similar to Kelsey's Diner. You will need to create a function called MQuote that selects a quote from a list of available quotes stored in an array. Another function, called RandInt, will return a random whole number from 0 to some specified maximum value. You can then use RandInt in conjunction with MQuote to select a quote to display on the page.
Add the following buttons to Calculator.html:
F->C for converting Farenheit to Celsius. For example, entering "212" into the calculator and pressing F->C should cause 100 to be displayed. To do this, define a function called FtoC() that gets called when the F->C button is clicked. This function does not need to take any input parameters, because it will get its input directly from the calculator display. The function should retrieve the current value from the display, convert it to Celsius, and then update the display.
C->F for converting Celsius to Farenheit.
n! for computing the factorial of a number. The factorial of a number n is just the product of 1 × 2 × 3 × ... × n. As a special case, the factorial of 0 is defined to be 1. Your function should use a loop to calculate the factorial value (either a while-loop or a for-loop will work). Make sure that your n! button works correctly for 0.
For each mystery function, choose a better name for it that describes what the function computes.
EXTRA CREDIT: Unfortunately, the calculator still has problems with the decimal point. It is possible to enter more than one decimal point for a single number. For example, you can enter "123.45.6" (try it). Modify the calculator code to correct this problem.
One way to approach this is to introduce an extra global variable that stores a true or false value, indicating whether or not the decimal key has been pressed. This variable is initially false, but can be set to true the first time the decimal key is clicked. Then, if the key is clicked again, pressed will know that the decimal point has already been entered, so it can just ignore the key click. Remember, however, to reset the variable back to false at the appropriate time, so that the decimal point can be used again for the next number.
Put the files for parts 1-4 into separate subfolders called Swapper, Kelsey, Twain, and Calculator. Put these subfolders into a folder called Your name HW 8 and drop it into the CS 10 drop box. For part 5, write out your answers on a piece of paper and turn this in during class.