Std 12th IT Subject - Skill Oriented Practical (Science Stream)
to and from Celsius, Fahrenheit. Formula: c/5= (f-32)/9
[where c=Temperature in Celsius and f=Temperature in Fahrenheit.]
<!DOCTYPE html>
<html>
<head>
<title>Temperature Converter</title>
</head>
<body>
<h2>Temperature Converter</h2>
<form name="f1">
Enter Temperature: <input type="number" name="Temp">
<select name="s1">
<option value="">Select Conversion</option>
<option value="Celsius">to Celsius</option>
<option value="Fahrenheit">to Fahrenheit</option>
</select>
<input type="button" value="Convert" onclick="ConvertTemp()">
</form>
<script>
function ConvertTemp() {
var temp = parseFloat(f1.Temp.value);
var convertto = f1.s1.value;
var ans;
if (convertto == "Fahrenheit") {
ans = (temp * 9 / 5) + 32;
alert("Temperature in Fahrenheit is: " + ans);
} else if (convertto == "Celsius") {
ans = (temp - 32) * 5 / 9;
alert("Temperature in Celsius is: " + ans);
} else {
alert("Select a Conversion type!");
}
}
</script>
</body>
</html>