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

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

11 months ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

11 months ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

11 months ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

11 months ago

Function/method to convert Celsius into Fahrenheit -Entered by user

Function/method to convert Celsius into Fahrenheit -Entered by user In this article, we will discuss…

11 months ago

Temperature conversion: Celsius into Fahrenheit using function or method

Temperature conversion: Celsius into Fahrenheit using a function or method In this article, we will…

11 months ago

This website uses cookies.