Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
Function/method to convert Celsius into Fahrenheit -Entered by user

JavaScript: Convert Fahrenheit degrees to Celsius

Posted on May 27, 2023May 27, 2023

Table of Contents

  • JavaScript: Convert Fahrenheit degrees to Celsius
    • Code to Alter Fahrenheit into Celsius
      • Convert Fahrenheit into Celsius  -#1
      • Convert Fahrenheit into Celsius  -Entered by the user-#2
      • Convert Fahrenheit into Celsius Using function – #3
      • Convert Fahrenheit into Celsius Using the function -Entered by user #4

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

 

 

 

 

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes