t() event handler functions call the toggleDisplay() helper function and pass it strings to display. Also note that the toggleDisplay() helper function and the convertTemp() event handler function are incomplete. 4. Code the toggleDisplay() function so it changes the text in the la
In this exercise, you’ll use radio buttons to determine whether the conversion is from Fahrenheit to Celsius or vice versa. You’ll also modify the DOM so the labels change when a radio button is clicked, and the page displays an error message when the user enters invalid data.
2. Note that the JavaScript file has some starting JavaScript code, including the $() function, three helper functions, three event handler functions, and a DOMContentLoaded event handler that attaches the three event handlers.
3. Review how the toCelsius() and toFarhenheit() event handler functions call the toggleDisplay() helper function and pass it strings to display. Also note that the toggleDisplay() helper function and the convertTemp() event handler function are incomplete.
4. Code the toggleDisplay() function so it changes the text in the labels for the text boxes to the values in the parameters that it receives. It should also clear the disabled text box where the computed temperature is displayed.
5. Code the convertTemp() function without any data validation. It should use the helper functions to calculate the temperature based on which radio button is checked. The value returned by the helper functions should be rounded to zero decimal places
![Currently Open Documents
* ~/Desktop/INF286/exercises_extra/ch06/convert_temps/convert_temp.js :
(functions) ©
O convert_temp.css
"use strict";
const $ = selector => document.querySelector(selector);
1
O index.html
O convert_temp.js
a register.js
3
4 ▼
/***
***
helper functions
**************/
5
******
const calculateCelsius = temp => (temp-32) * 5/9;
const calculateFahrenheit =
7
8.
temp => temp * 9/5 + 32;
9.
10
const toggleDisplay
(label1Text, label2Text) => {
%3D
11
12
13
14 ▼
/****
****
15
event handler functions
16
******
*********************/
const convertTemp
() => {
17
18
19
};
20
() => toggleDisplay("Enter F degrees:", "Degrees Celsius:");
()
21
const toCelsius =
22
const toFahrenheit =
toggleDisplay("Enter C degrees:", "Degrees Fahrenheit:");
=>
23
document.addEventListener ("DOMContentLoaded", () => {
// add event handlers
$("#convert").addEventListener("click", convertTemp);
$("#to_celsius").addEventListener("click", toCelsius);
$("#to_fahrenheit").addEventListener("click", toFahrenheit);
24
25
26
27
28
29
// move focus
$("#degrees_entered").focus( );
});
30
31
32 -
L: 18 C: 1
JavaScript :
Unicode (UTF-8) :
Windows (CRLF) *
Saved: 12/3/21, 5:08:06 PM
901 / 68 / 32 Q -
100% :](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0f280fe7-33d7-45ee-88a8-46c08afcb827%2F4ace0557-2b5f-4a34-93b1-a49851257876%2Fmljoayr_processed.png&w=3840&q=75)
![Currently Open Documents
* ~/Desktop/INF286/exercises_extra/ch06/convert_temps/index.html :
(no function selected) :
O convert_temp.css
1
<!DOCTYPE html>
© index.html
2 ▼
<html>
<head>
O convert_temp.js
A register.js
3 ▼
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Convert Temperatures</title>
<link rel="stylesheet" href="convert_temp.css">
</head>
6.
7
8.
9.
<body>
<main>
<h1>Convert temperatures</h1>
10
11
▼
12
13
<div>
▼
<input type="radio" name="conversion_type" id="to_celsius" checked>Fahrenheit to Celsius
</div>
<div>
14
15
16
<input type="radio" name="conversion_type" id="to_fahrenheit">Celsius to Fahrenheit
</div>
17
18
19
<div>
<label id="degree_label_1">Enter F degrees:</label>
<input type="text" id="degrees_entered">
</div>
20
21
22
23
<div>
▼
<label id="degree_label_2">Degrees Celsius:</label>
<input type="text" id="degrees_computed" disabled>
</div>
24
25
26
27
<div>
28
<label></label>
<input type="button" id="convert" value="Convert" />
</div>
29
30
31
</main>
<script src="convert_temp.js"></script>
</body>
</html>
32
33
34
L: 1 C: 1
HTML :
Unicode (UTF-8) :
Windows (CRLF) :
Saved: 6/27/21, 3:36:00 PM
883 / 105 / 34 Q -
100% :](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0f280fe7-33d7-45ee-88a8-46c08afcb827%2F4ace0557-2b5f-4a34-93b1-a49851257876%2F14ytjf9_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)