Using a switch case statement write a program to convert temperature from Fahrenheit to Celsius and vice versa.
for an incorrect choice on appropriate message should be displayed.
Hint: c=5/9*(f-32) and f=1.8*c+32
Answers
Hi
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Temperature Converter</title>
</head>
<body>
<script>
const temperature = parseInt(prompt("Enter temperature"));
let covertTo = prompt("Covert to: (f/c)");
switch (covertTo) {
case "f":
document.write(`${temperature} Celsius in Fahrenheit will be ${(((temperature * 9) / 5) + 32)}`);
break;
case "c":
document.write(`${temperature} Fahrenheit in Celsius will be ${(((temperature - 32) * 5) / 9)}`);
break;
default:
document.write("Please enter valid temperature and covert");
break;
}
</script>
</body>
</html>
just copy and paste this code in html file and execute it in browser.