Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Fahrenheit – Celcius

Fahrenheit – Celcius

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:

Loading

Views: 161

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments