c/articles 1 2 3. In your text editor, open index.htm from the HandsOn Project2-1 folder in the Chapter02 folder. Enter your name and today's date where indicated in the comment section in the document head. At the bottom of the document, before the closing
tag, enter insert a blank line, and then enter to create a new script section Within the script section you created in the previous step, enter the following function. function convert var degF - document.getElementById("Value").values war deg degr - 3259; document.getElementById("Value").innerHTML degC) 3 3 This function, named convert 1), starts by looking up the Fahrenheit value entered by users and assigning it to a variable named degf. It then performs calculations on degF to arrive at the Celsius equivalent, which is assigned to a variable named degc. Finally, it assigns the value of dege as the innerHTML value of the element with the id value Value 4. Below the closing ) for the convert() function, but before the closing tag, enter the following statement to add an event listener: document.getElementById("button"). addEventListener("click", convert, false) 5. Save your work, open index.htm in your browser, enter-40 in the Enter temp in F box, and then click the Convert to C button. -40 Fahrenheit is actually equivalent to -40 Celsius. However, the formula incorrectly calculates that -40 F is equivalent to -57.7C. This is because the calculations in the equation must take place in a different order than the order of precedence dictates. 6. Return to the index.htm file in your text editor, and then add two sets of parentheses to the first statement in the convert() function to modify the order in which the calculations are performed, as follows: var degc = degs 32) - 15/9): 7. Save your work, refresh or reload index.htm in your browser, enter - 40 in the Enter temp in F box, and then click the Convert to C button. As Figure 2-18 shows, the temperature is now calculated correctly as -40C
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance