Use Javascript with Loops to edit the code to do the following: <!DOCTYPE html>
ID: 3870730 • Letter: U
Question
Use Javascript with Loops to edit the code to do the following:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Convert from Fahrenheit to Centigrade</title>
<script>
EDIT HERE
</script>
</head>
<body>
<main>
<h1>Thanks for using the temperature converter</h1>
</main>
</body>
</html>
An application interface that converts Fahrenheit temperatures to Celsius temperatures by using prompt and alert statements.
The prompt dialog box will ask the user to input a Farenheit temperature.
If it's a valid data entry, an alert dialog box should open showing the Farenheit temperature, the Celsius temperature, and a checkbox to prevent the page from creating additional dialogs.
If an invalid data is entered, then an alert should pop up showing the data entered, and the range of acceptable values: (-100 to +212), as well as a checkbox to prevent the page from creating additional dialogs.
Lastly, add a loop to the code so the user can do a series of calculations without restarting the application. To end the application, the user must enter 999 as the temperature.
Explanation / Answer
while(true){
faren = prompt("Enter Farenheit Temperature:");
//get valied input
while(faren<-100 || (faren>212 && faren!=999)){
alert(faren+" Is invalid. acceptable values:(-100 to +212)");
faren = prompt("Enter Farenheit Temperature:");
}
//break loop if input is 999
if(faren==999){
break;
}
//convert farenheit to Celcius
var celc = (faren-32)*(5/9.0);
alert("Farenheit:"+faren+" Celcius:"+celc);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.