1
Program 1
Aim (Write on the ruler page)
Create event driven JavaScript program to convert temperature to and from Celsius, Fahrenheit.
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.
Program (Start from new page after AIM)
<!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>
Output (Stick on blank page opposite to code)
Download Output