How to usethe formula with a custom function in Javascript
In this approach, we are using a javascript custom function and applying the formula: Fahrenheit = (Celsius * 9/5) + 32. For a given temperature of 20°C.
Syntax:
function celcToFahr( n ) {
return ((n * 9.0 / 5.0) + 32.0);
}
Example: In this example, we are using the above-mentioned approach.
Javascript
// Javascript Program to convert Temperature // from Celsius to Fahrenheit // function to convert Celsius // to Fahrenheit function celcToFahr( n ) { return ((n * 9.0 / 5.0) + 32.0); } // Driver code const n = 20; console.log(celcToFahr( n )); |
Output
68
JavaScript Program to Convert Celsius to Fahrenheit
Fahrenheit and centigrade are the two most used temperature scales and we often need to convert Celsius to Fahrenheit. In this article, we are going to learn how to Convert Celsius to Fahrenheit.