Deliverables:
To complete this assignment you must --
1.) Write the HTML and JavaScript page described below and demonstrate to
the lab instructor that it operates correctly.
Introduction: The goal of this assignment is to allow you to become familiar with converting algorithms to JavaScript and to become familiar with a few basic JavaScript commands.
Procedures:
PART 1:
Section | Pseudocode | Comments |
---|---|---|
INPUT: | Number far1, far2, far3; | |
OTHER VARIABLES: | Number cent1, cent2, cent3; | We'll use these variables to store the results. |
INITIALIZATION: | far1 = 32; far2 = 78; far3 = 212; |
Storing initial values for the Fahrenheit temps in memory. |
COMPUTATION: | cent1 = 5 * (far1 - 32) / 9; cent2 = 5 * (far2 - 32) / 9; cent3 = 5 * (far3 - 32) / 9; |
Converting F - C using the standard formula. Notice how innefficient this repetition is - imagine doing 1,000,000. |
OUTPUT: | return(cent1, cent2, cent3); | Notice the algorithm doesn't say anything about format. You take care of that when You write the JavaSCript. |
Section | Pseudocode | Comments | |
---|---|---|---|
INPUT: | Number subtotal; | ||
OTHER VARIABLES: | Number taxrate; Number salestax; Number total; |
Why do you think taxrate is not an input variable? Could it be? Should it be? | |
INITIALIZATION: | taxrate = 0.06; subtotal = 57.24; | ||
COMPUTATION: | salestax = subtotal * taxrate; salestax = Math.round(salestax * 100 ); salestax = salestax / 100; total = subtotal + salestax; |
If you are unsure of what the middle two lines are doing, try leaving them out and running the code. Math.round() is one of hundreds of functions JavaScript provides to you. | |
OUTPUT: | return(subtotal, total); | Note we aren't returning the tax rate or amount of tax. |