Table of Contents
show
Example 5:
Create a variable called “temperature” and assign it a numerical value representing the current temperature in Celsius. Convert this temperature to Fahrenheit and store the result in a new variable called “fahrenheit”. Finally, log the value of “fahrenheit” to the console.
Formula Used
Celsius to Fahrenheit: F = (C * 9/5) + 32
Fahrenheit to Celsius: C = (F – 32) * 5/9
let temperature = 23;
let F = (temperature * 9) / 5 + 32;
console.log("Fahrenheit=" + F);
let C = ((F - 32) * 5) / 9;
console.log("celcius=" + C);
Output:
Views: 161