-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempCon.js
54 lines (44 loc) · 1.71 KB
/
tempCon.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// const calculateTemp = () => {
// const inputTemp = document.getElementById("temp").value;
// const tempSelected = document.getElementById("temp_diff");
// const valueTemp = temp_diff.options[tempSelected.selectedIndex].value;
// // 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" ) {
// const newLocal = document.getElementById("result").innerHTML = celToFah(inputTemp) + "° Fahrenheit";
// }
// else{
// document.getElementById("result").innerHTML = `${fahToCel(inputTemp)}° Celsius`
// }
// }
const calculateTemp = () => {
const inputTemp = parseFloat(document.getElementById("temp").value);
const tempSelected = document.getElementById("temp_diff");
const valueTemp = tempSelected.options[tempSelected.selectedIndex].value;
const celToFah = (cel) => {
return ((cel * 9/5) + 32).toFixed(1) + "° Fahrenheit";
}
const fahToCel = (fah) => {
return ((fah - 32) * 5 / 9).toFixed(1) + "° Celsius";
}
const kalToCel = (kel) => {
const celsius = (kel - 273.15).toFixed(1);
return celsius + "° Celsius";
}
const resultElement = document.getElementById("result");
if (valueTemp === "cel") {
resultElement.innerHTML = celToFah(inputTemp);
} else if(valueTemp === "fah") {
resultElement.innerHTML = fahToCel(inputTemp);
}else{
resultElement.innerHTML = kalToCel(inputTemp)
}
}