-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (28 loc) · 1.04 KB
/
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
28
29
30
31
32
33
const calculateTemp = () => {
const inputTemp = document.getElementById('temp').value;
const tempSelected = document.getElementById('temp_diff');
const valueTemp = temp_diff.options[tempSelected.selectedIndex].value;
// kelvin to Celsius
const kelTocel = (cel) => {
let kelvin = (inputTemp - 273.15).toFixed(1);
return kelvin;
}
// Celsius to Fahrenheit
const celToFah = (cel) => {
let fahrenheit = ((cel * 9 / 5) + 32).toFixed(1);
return fahrenheit;
}
// Fahrenheit to Celsius
const fahToCel = (fah) => {
let celsius = ((fah - 32) * 5 / 9).toFixed(1);
return celsius;
}
if (valueTemp == 'cel') {
document.getElementById("result").innerHTML = celToFah(inputTemp) + "° Fahrenheit";
}
else if (valueTemp == 'fahrenheit'){
document.getElementById("result").innerHTML = fahToCel(inputTemp) + "° Celsius";
}else{
document.getElementById("result").innerHTML = kelTocel(inputTemp) + "° Celsius";
}
}