calculations

JavaScript: Convert Fahrenheit degrees to Celsius

JavaScript: Convert Fahrenheit degrees to Celsius

In this article, we will discuss the concept of “JavaScript: Convert Fahrenheit degrees to Celsius”

In this post, we will learn how to write a program to convert Fahrenheit into Celsius.

Here, we have four methods and explain how to calculate Celsius using the given Fahrenheit value and display the result on the screen in JavaScript programming language.

Code to Alter Fahrenheit into Celsius

Convert Fahrenheit into Celsius  -#1

In this program, the user declares two variables celsius and fahrenheit, and initiates the value as 68.0 to Fahrenheit. Then the scientific equation will convert from Fahrenheit into Celsius in the JavaScript programming language.

Program 1

//Code to Convert Fahrenheit to Celsius
//Take input from the user
const fahrenheit=68;
const celsius=(fahrenheit-32)*5/9;
//Calculate temperature of Celsius
//Display the result on the screen
console.log(`${fahrenheit} degrees Fahrenheit is equal to ${celsius} degrees Celsius.` );

When the above code is executed, it produces the following result

68 degrees Fahrenheit is equal to 20 degrees Celsius.

 

Convert Fahrenheit into Celsius  -Entered by the user-#2

In this program, the user declares two variables as Celsius and Fahrenheit. The program asks for the value from the user to Fahrenheit then the given input will convert from Fahrenheit into Celsius in the JavaScript programming language using the scientific equation.

Program 2

//code to Convert Fahrenheit to  Celsius
//Ask input from the user
const fahrenheit=prompt("Enter a Fahrenheit value: ");
const celsius=(fahrenheit-32)*5/9;
//Calculate temperature of Celsius
//Display the result on the screen
console.log(`${fahrenheit} degrees Fahrenheit is equal to ${celsius} degrees Celsius.` );

When the above code is executed, it produces the following result

Enter a Fahrenheit value: 212
212 degrees Fahrenheit is equal to 100 degrees Celsius.

 

Convert Fahrenheit into Celsius Using function – #3

In this program, the user declares a  variable as a parameter for Fahrenheit(f) in the user-defined function. When the user runs the program (when calling the function), the value of  Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 3

//Program to Convert Fahrenheit to Celsius 
function fahreToCels(f){ 
return (fahrenheit-32)*5/9; 
//function definition 
}
 const fahrenheit=98.6; 
//declare and initialize variable
var result=fahreToCels(fahrenheit) 
//Calling the function 
//Display the result
 console.log(`${fahrenheit} degrees Fahrenheit is equal to ${result} degrees Celsius.` );

 

When the above code is executed, it produces the following result

98.6 degrees Fahrenheit is equal to 37 degrees Celsius.

 

Convert Fahrenheit into Celsius Using the function -Entered by user #4

In this program, the user declares a double variable as a parameter for Fahrenheit(F) in the user-defined function. When the user runs the program (when calling the function), the user is asked to enter the value of Fahrenheit and then the value of  Fahrenheit passes as an argument to the function.
Finally, the Celsius value is calculated and displayed on the screen using the scientific equation.

Program 4

//Program to Convert Fahrenheit to  Celsius
function fahreToCels(f){
    return (fahrenheit-32)*5/9;
    //function definition
}
const fahrenheit=prompt("Enter a Fahrenheit value: ");
//Take input from the user
var result=fahreToCels(fahrenheit)
//Calling the function
//Display the result
console.log(`${fahrenheit} degrees Fahrenheit is equal to ${result} degrees Celsius.` );

When the above code is executed, it produces the following result

Enter a Fahrenheit value: 32
32 degrees Fahrenheit is equal to 0 degrees Celsius.

 

Similar post

Celsius into Fahrenheit in the C program

Fahrenheit into Celsius in C program

Celsius into Fahrenheit in C++ program

Fahrenheit into Celsius in C++ program

Celsius into Fahrenheit in the C# program

Fahrenheit into Celsius in C# program

Convert Celsius into Fahrenheit in Python

Convert Fahrenheit into Celsius in Python

Convert Celsius into Fahrenheit in PHP

Convert Fahrenheit into Celsius in PHP

Convert Celsius into Fahrenheit in JavaScript

Convert Fahrenheit into Celsius in JavaScript

 

 

 

 

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

3 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

3 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

4 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

4 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

4 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

4 months ago

This website uses cookies.