-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.html
60 lines (54 loc) · 1.85 KB
/
temperature.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Temperature Converter</title>
<link rel="stylesheet" href="temperature.css">
<div class="container">
<h1><br>
Temperature Converter
<img src="https://cdn-icons-png.flaticon.com/512/2100/2100100.png" /></h1>
<div class="converter-row">
<div class="col">
<label>Fahrenheit</label>
<input type="number" id="fahrenheit">
</div>
<div class="col">
<label>Celsius</label>
<input type="number" id="celsius">
</div>
<div class="col">
<label>Kelvin</label>
<input type="number" id="kelvin">
</div>
</div>
</div>
<script>
let celsius = document.getElementById('celsius');
let fahrenheit = document.getElementById('fahrenheit');
let kelvin = document.getElementById('kelvin');
celsius.oninput = function () {
let f = (parseFloat(celsius.value) * 9) / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
let k = (parseFloat(celsius.value) + 273.15);
kelvin.value = parseFloat(k.toFixed(2));
}
fahrenheit.oninput = function () {
let c = ((parseFloat(
fahrenheit.value) - 32) * 5) / 9;
celsius.value = parseFloat(c.toFixed(2));
let k = (parseFloat(
fahrenheit.value) - 32) * 5 / 9 + 273.15;
kelvin.value = parseFloat(k.toFixed(2));
}
kelvin.oninput = function () {
let f = (parseFloat(
kelvin.value) - 273.15) * 9 / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
let c = (parseFloat(kelvin.value) - 273.15);
celsius.value = parseFloat(c.toFixed(2));
}
</script>
</body>
</html>