Fahrenheit to Celsius converter


#1

I get no errors, but it won’t work.

<script>
	"use strict";
	var again;
	do {
		do {
			var userInput = prompt("Enter Fahrenheit temperature");
			if (isNaN(userInput) || userInput < -100 || userInput > 212) {
				alert("You entered " + userInput + "/n Entry must range from -100 to +212);
			}
			userInput = parseInt(userInput);
			}
		while (isNaN(userInput) || userInput > -100 || userInput < 212)
			var celsius = (userInput - 32) * (5 / 9);
			alert("Fahrenheit temperature is " + userInput + "/n Celsius temperature is " celsius);
			again = prompt("Interested in another temperature conversion?", "y");
		}
	while (again == "y");	
		
</script>


#2

You’re missing a quote on this line. You can often tell by most code editors color method, i.e., the text following this line is mostly red, which shows you that it’s recognized as a string.


#3

To simplify your main program, abstract away the functions…

const toFahrenheit = celsius => 9 * celsius / 5 + 32;

const toCelsius = fahrenheit => 5 * (fahrenheit - 32) / 9;

That lets one focus on user input and reporting results.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.