0% found this document useful (0 votes)
4 views2 pages

Program15 HTML

The document outlines a JavaScript program that creates a temperature converter for Celsius and Fahrenheit. It includes an algorithm detailing the steps to accept user input, perform the conversion, and display the result. The program is implemented in HTML with JavaScript functions to handle the conversions.

Uploaded by

jgame3145
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Program15 HTML

The document outlines a JavaScript program that creates a temperature converter for Celsius and Fahrenheit. It includes an algorithm detailing the steps to accept user input, perform the conversion, and display the result. The program is implemented in HTML with JavaScript functions to handle the conversions.

Uploaded by

jgame3145
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

15.

JavaScript Program to Create a Temperature Converter

ALGORITHM:

1. Start the program


2. Display input field and conversion buttons on the webpage
3. Accept temperature value entered by the user
4. Detect the button click event (Celsius → Fahrenheit or Fahrenheit → Celsius)
5. Read the input value using JavaScript (getElementById)
6. Perform the conversion using the appropriate formula and store the result
7. Display the result on the screen and stop

PROGRAM 15:
<!DOCTYPE html>
<html>
<body>
<h3>Temperature Converter</h3>

Enter Temperature:
<input type="number" id="t"><br><br>

<button onclick="cToF()">Celsius → Fahrenheit</button>


<button onclick="fToC()">Fahrenheit → Celsius</button>
<p id="out"></p>
<script>
function cToF(){
let c = [Link]("t").value;
let f = (c * 9/5) + 32;
[Link]("out").innerHTML = "Fahrenheit: " + f;
}
function fToC(){
let f = [Link]("t").value;
let c = (f - 32) * 5/9;
[Link]("out").innerHTML = "Celsius: " + c;
}
</script>
</body>
</html>

OUTPUT:

You might also like