-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (22 loc) · 787 Bytes
/
index.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
const calculateTemp = () => {
const inputTemp = document.getElementById("temp").value;
const tempSelected = document.getElementById("temp_diff");
const valueTemp = temp_diff.options[tempSelected.selectedIndex].value;
// Celcius To Fahrenheit
const celtoFah = (cel) => {
let fahrenheit = ((cel * 9 / 5) + 32).toFixed(1);
return fahrenheit;
}
// Fahrenheit to Celcius
const fahtoCel = (fah) => {
let celcius = ((fah - 32) * 5 / 9).toFixed(1)
return celcius;
}
if(valueTemp == "cel"){
document.getElementById("result").innerHTML=celtoFah(inputTemp) + "° Fahrenheit";
}
else{
document.getElementById("result").
innerHTML =fahtoCel(inputTemp) + "° Celcius";
}
}