Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Celsius returns the Celsius equivalent of a Fahrenheit temperature, usi

ID: 3532630 • Letter: F

Question

Function Celsius returns the Celsius equivalent of a Fahrenheit temperature, using the calcuation: C = 5.0 / 9.0 * (F-32);

Function fahrenheit returns the Fahrenheit equvalent of a Celsius temperature, using the calculation: F = 9.0/5.0 * C +32;

Use these functions to write a script that enables the user to enter eigher a Fahrenheit or a Celsius temperature and displays the Celsius or Fahrenheit equivalent. The HTML5 document should contain two buttons -- one to initiate the conversion from Fahrenheit to Celsius and one to initiate the conversion from Celsius to Fahrenheit.

Explanation / Answer

Here you go, tried to simplify as much as possible :


<html>

<head>

<script type="text/javascript">

function Celsius()

{

var f= document.getElementById("fVal").value;

document.getElementById("cVal").value=(5/9)*(f-32);

}

function Fahrenheit()

{

var c= document.getElementById("cVal").value;

document.getElementById("fVal").value=(9/5)*c+32;

}

</script>

</head>

<body>

<input type=text id="cVal" placeholder="Enter Temperature in Celsius"/>

<input type=text id="fVal" placeholder="Enter Temperature in Fahrenheit"/>

<button>CelciusToF</button>

<button>FahrenheitToC</button>

</body>

</html>