Computer Science, asked by Harshi666, 1 year ago

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

Answered by Anonymous
2

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.



Harshi666: yeah... cause we were chatting
Harshi666: but I have many questions unanswered.. so we can text there
Harshi666: hm
Similar questions