-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
58 lines (52 loc) · 2 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1.0"/>
<title>Dynamic Temperature Converter</title>
<link rel="stylesheet" href="styles.css" />
<link rel="icon" href="temperature-sensor.png"/>
</head>
<body>
<div class="container">
<h1>Temperature converter</h1>
<div class="converter_row">
<div class="col">
<label>Fahrenheit</label>
<input type="number" id="fahrenheit" placeholder="°F">
</div>
<div class="col">
<label>Celsius</label>
<input type="number" id="celsius" placeholder="°C">
</div>
<div class="col">
<label>Kelvin</label>
<input type="number" id="kelvin" placeholder="°K">
</div>
</div>
</div>
<script>
const celsius=document.getElementById('celsius');
const fahrenheit=document.getElementById('fahrenheit');
const 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 c = (parseFloat(kelvin.value) - 273.15);
celsius.value = parseFloat(c.toFixed(2));
let f = (parseFloat(kelvin.value) - 273.15) * 9 / 5 + 32;
fahrenheit.value = parseFloat(f.toFixed(2));
};
</script>
</body>
</html>