-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
27 lines (22 loc) · 855 Bytes
/
script.js
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
const celciusEl = document.getElementById("Celcius");
const fahrenheitEl = document.getElementById("Fahrenheit");
const kelvinEl = document.getElementById("Kelvin");
function computeTemp(event) {
const currentValue = event.target.value;
switch (event.target.name) {
case "Celcius":
fahrenheitEl.value = (currentValue * 9 / 5) + 32;
kelvinEl.value = parseFloat(currentValue) + 273.15;
break;
case "Fahrenheit":
celciusEl.value = (currentValue - 32) * 5 / 9;
kelvinEl.value = (currentValue - 32) * 5 / 9 + 273.15;
break;
case "Kelvin":
celciusEl.value = currentValue - 273.15;
fahrenheitEl.value = (currentValue - 273.15) * 9 / 5 + 32;
break;
default:
break;
}
}