Due 1:30 PM, Wednesday, 07 March 2018 CPSC 101b Homework #5 JavaScript: Straight-line Code Note: Your solutions to these problems (i.e., the files hello.html, fpf.html, and pp.html) should be sent as attachments in a message to sce@cs.yale.edu by the time+date above. The subject line should contain the phrase "CPSC 101". REMINDER: When discussing an assignment with other students, you may write on a board or a piece of paper, but you may not retain any written or electronic record of the discussion. Moreover, you must engage in a full hour of mind- numbing activity (e.g., watching back-to-back episodes of Gilligan's Island) before you work on the assignment again. This ensures that you can reconstruct what you learned from the discussion, by yourself, using your own brain. The same rule applies to nonstudents and on-line sources. 1. (5 points) Using the Chrome or Safari browser, go to the class web site https://zoo.cs.yale.edu/classes/cs101 and click on the "Hello, world!" link in the "Homework Assignments" section. This page is a simple JavaScript program that opens a pop-up window saying "Hello, world!". Click on "OK" to dismiss the pop-up. You can run the program again by typing COMMAND-R (MacOS) or CTRL-R (Windows). You can view the program source by typing Chrome (1) Safari (2) MacOS OPTION-COMMAND-U OPTION-COMMAND-U Windows CTRL-SHIFT-I CTRL-ALT-U (1) Then click on the "Sources" tab and "hello.html" if necessary. (2) If there is no "Develop" menu in the menu bar, you must first type COMMAND-, (MacOS) or CTRL-, (Windows) to open the Preferences window; select the "Advanced" tab; and click on "Show Develop menu in menu bar". Type COMMAND-S (MacOS) or CTRL-S (Windows) to save the program as a type HTML file, i.e., as Chrome Safari (*) MacOS Webpage, HTML only Page Source Windows Webpage, HTML only HTML Files Give the saved file the name hello.html. Use TextEdit (Mac) or NotePad (Windows) or some other editor to: * Change my name and my userid to yours. * Change "Hello, world!" to some other phrase. * Save the changes. See Note (a) below for further details. Back in the browser, run the modified program by typing COMMAND-O (MacOS) or CTRL-O (Windows), navigating to the file, and opening it. The behavior should be the same as before, except for what appears in the pop-up window. Notes ~~~~~ a. To modify hello.html: (MacOS) Start TextEdit; type COMMAND-, to open the Preferences window; switch to the "Open and Save" pane; and set "Display HTML files as HTML code instead of formatted text". Then type COMMAND-O; navigate to the folder containing the file; select the file; and open it. After making the changes, type COMMAND-S to save them and COMMAND-Q to exit. (Windows) Start NotePad. Then type CTRL-O; navigate to the directory containing the file; specify "All Files" instead of "Text Documents" so that it is listed; select the file; and open it. After making the changes, type CTRL-S to save them and exit. ["Save As..." in the "File" menu lets you save the program with a different name.] The instructions may differ if you use a different word processor. b. If the browser displays code when you run a program, the file probably has the wrong extension (e.g., .txt instead of .html). Rename the file or resave it to give it a .html extension, and try again. c. If the browser window is blank when you run a program, there are probably syntax errors that prevented JavaScript from executing it. To check, open the JavaScript console by typing Chrome Safari (*) MacOS OPTION-COMMAND-J OPTION-COMMAND-C Windows CTRL-SHIFT-J CTRL-ALT-C (*) If there is no "Develop" menu in the menu bar, you must first type COMMAND-, (MacOS) or CTRL-, (Windows) to open the Preferences window; select the "Advanced" tab; & click on "Show Develop menu in menu bar". Click on filename:line to see the source with the error highlighted. After using TextEdit (MacOS) or NotePad (Windows) to (try to) fix the problem, rerun the program by typing COMMAND-R (MacOS) or CTRL-R (Windows) in the browser and verify that your changes are correct. If not, try again. 2. (6 points) Write a Javascript program that * Prompts for a velocity in units of centimeters per second, the standard for the classical CGS system of units, described at https://en.wikipedia.org/wiki/Centimetrebgrambsecond_system_of_units * Displays the same velocity in furlongs per fortnight, the standard for the new FFF (Furlong/Firkin/Fortnight) system of units, described at https://en.wikipedia.org/wiki/FFF_system For example, when the input is 127 centimeters/second, the output should look something like: 127.00 centimeters/second = 7636.36 furlongs/fortnight (numbers are displayed with two digits to the right of the decimal point). Your program may output to either an alert box or a document and should be embedded in a file called fpf.html that contains (e.g., in the title or in a comment) your name, your Yale netid, and how long you took to complete it. Note: You may assume that 1 inch = 2.54 centimeters. 3. (10 points) At Palermo Pizza white clam and bacon slices cost $1.99, whole pies (= 8 slices) cost $12.00, soft drinks cost $1.25, and the Connecticut sales tax is 6%. Write a Javascript program that * Prompts for the number of slices and the number of soft drinks ordered. * Displays the order and the price, including tax, in dollars and cents. For example, when the input is 10 slices and 5 drinks, the output should look something like: 10 slices and 5 drinks = $22.23 + $1.33 tax = $23.56 since 10 slices = 1 pie + 2 slices. (Note that amounts of money are displayed with a leading $ and 2 digits to the right of the decimal point; and that the total, the tax, and the grand total are all shown.) Your program may output to either an alert box or a document and should be embedded in a file called pp.html that contains (e.g., in the title or in a comment) your name, your Yale netid, and how long you took to complete it. Hint: You can use % to compute the number of odd slices. CPSC-101b-02/21/18