Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4.28LAB: Temperature converter In this lab, you will implement a temperature converter in .lava Script. The user may type a temperature in either the Celsius
4.28LAB: Temperature converter In this lab, you will implement a temperature converter in .lava Script. The user may type a temperature in either the Celsius or Fahrenheit. textbox and pres s Convert to convert the temperature. An image dis plays based on the converted temperature. Temperature Converter Convert The given HTML template declares five Ul ekments: Implement conversion functions (2 points) Impkement the convertCtoF() and convertFtoC0 functions to convert between Celsius and Fahrenheit. convertCtoF() takes a singk numerical argument for a temperature in Celsius and returns the temperature in Fahrenheit using the following convers ion formula: F=C9/5+32 Similarly, convertFtoC() takes a singk numerical argument for a temperature in Fahrenheit and returns the temperature in Celsius us ing the following conversion formula: C=(F32)5/9 Register convert button's click event handler (2 points) When the DOM finishes loading, the domLoaded0 function is calke. Implement domLoaded0 to register a click event handker for the Convert button (id= "convertButton"). Use addeventListener(), not onclick When the Convert butt on is pressed, the text box that contains a number should be converted into the opposing temperature. So if a number is in the Celsius text box (id="clnput"), the temperat ure should be converted into Fahrenheit and displyed in the Fahrenheit text. box (id='flnput") and vice versa. Use parseFloat() to convert from a string to a number and do not round the result. Ensure anly ane text field contains a value (2 points) Ensure that only one text field contains a value at any moment in time unless the Convert button has been pressed. Ex: When the Celsius field has a number and the user enters a Fahrenheit entry the Celsius field should be cleared as soon as the user begins to type. This will require implementing an input event hander for each of the text fields that clears the opposing text field when a change occurs. Register each input event hander in the domLoaded0 function. Use addeventListener0, not oninput. Change image to reflect temperature (2 points) When the temperature is converted, change the image to refect the temperature in Fahrenheit. Each image is in the same directory as your .html fik. To change the image, change the image's sro property to the appropriate filename Handle bad input (2 points) When parsefloat 0 returns NaN for the temperature to be converted, set errorMessage's innerHTML to the mes sage: " is not a number', where X is the string from the text input. When parseFloat 0 returns a valid number, set errorMessage's innerHTML to an emptystring. The image below shows a sampk error message Temperature Converter Convert really cold is not a number LABACTNTY4.28.1:LAB:Temperatureconverer Submission Instructions
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
Get Started