Exp-11 Create event driven JavaScript program to convert temperature to and from Celsius, Fahrenheit.

write this on the writing side

Formula: c/5= (f-32)/9
[where c=Temperature in Celsius and f=Temperature in Fahrenheit.]
Output format : 40 Celsius=104 Fahrenheit
45 Fahrenheit = 7.22222222 Celsius

<!DOCTYPE html>
<html>
<head>
<title></title>
<body>
<h2>JavaScript code to convert Celcius to Fahrenhiet or
vice-versa</h2>
<br>
<p>Enter the Temperature</p>
<p><input type="text" id="txt_celsius"
onkeyup="convert('C')"> Temperature in degree Celsius</p>
<br>
<p><input type="text" id="txt_fah"
onkeyup="convert('F')"> Temperature in degree
Fahrenheit</p>
<script>
function convert(temperature) {
var t;
if (temperature == "C")
{
t = document.getElementById("txt_celsius").value * 9
/ 5 + 32;
document.getElementById("txt_fah").value =
Math.round(t);
}
else
{

t = (document.getElementById("txt_fah").value -32) *
5 / 9;
document.getElementById("txt_celsius").value = (t);
}
}
</script>

</body>
</html>

stick this output on the blank side

Leave a Comment

Scroll to Top