-
Notifications
You must be signed in to change notification settings - Fork 12
/
temp_conv.html
79 lines (71 loc) · 2.32 KB
/
temp_conv.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<style>
/* css for styling and enabling dark background */
body {
background-color: black;
}
h2 {
text-align: center;
font-weight: lighter;
font-size: 60px;
margin-top: 0px;
color: white;
}
p {
text-align: center;
font-size: 30px;
margin-top: 60px;
color: white;
}
input[type="number"] {
text-align: center;
align-items: center;
margin-right: 50px;
padding: 10px;
}
</style>
</head>
<body>
<h2>Temperature Converter!</h2>
<p>Enter the value in any unit to automatically convert it to the other two units</p>
<p>
<label>Fahrenheit</label>
<input type="number" id="fahrenheit">
</p>
<p>
<label>Celsius</label>
<input type="number" id="celsius">
</p>
<p>
<label>Kelvin</label>
<input type="number" id="kelvin">
</p>
<!-- made three input boxes that give output when the other boxes are changed -->
<script>
var celsius = document.getElementById('celsius');
var fahrenheit = document.getElementById('fahrenheit');
var kelvin = document.getElementById('kelvin');
celsius.oninput = function () {
var f = (parseFloat(celsius.value) * 9) / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
var k = (parseFloat(celsius.value) + 273.15);
kelvin.value = parseFloat(k.toFixed(2));
}
fahrenheit.oninput = function () {
var c = ((parseFloat(fahrenheit.value) - 32) * 5) / 9;
celsius.value = parseFloat(c.toFixed(2));
var k = (parseFloat(fahrenheit.value) - 32) * 5 / 9 + 273.15;
kelvin.value = parseFloat(k.toFixed(2));
}
kelvin.oninput = function () {
var f = (parseFloat(kelvin.value) - 273.15) * 9 / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
var c = (parseFloat(kelvin.value) - 273.15);
celsius.value = parseFloat(c.toFixed(2));
}
// defining the variables and then suitably applying the formulae to get the results rounded to 2 decimal places
</script>
</body>
</html>