Introduction In this article we will be learning about converting celsius to fahrenheit in Javascript. Celsius to Fahrenheit is the conversion of temperature from Celsius unit to Fahrenheit unit. Steps to convert from Celsius to Fahrenheit
- Multiply Celsius value by 9/5
- Add 32 to Celsius value
Example
We will create function which will convert celsius to fahrenheit.
//declare variable
let celsius = 10;
let fahrenheit = 0;
//method to convert celsisus to fahrenheit
function celsiusToFahrenheit(celsius) {
return celsius*(9/5)+32;
}
//update fahrenheit value from celsisus to fahrenheit conversion method
fahrenheit = celsiusToFahrenheit(celsius)
//display results
console.log('celsius : ' + celsius );
console.log('fahrenheit : ' + fahrenheit );
Output
"celsius : 10"
"fahrenheit : 50"
Here we have declared two variables celsius,temperature and created a function that will convert celsius into fahrenheit from standard formula.We then update the fahrenheit value we set at 0 before to the value we obtained from the celsius to fahrenheit conversion method.