-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (22 loc) · 819 Bytes
/
script.js
File metadata and controls
27 lines (22 loc) · 819 Bytes
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 calculateTemp = () => {
const numberTemp = document.getElementById('temp').value;
const tempSelected = document.getElementById('temp_diff');
const valueTemp = tempSelected[tempSelected.selectedIndex].value;
const celTofah = (cel) => {
let fahrenheit = Math.round((cel * 9/5) + 32);
return fahrenheit;
}
const fahTocel = (fah) => {
let celsius = Math.round((fah - 32 ) * 5/9);
return celsius;
}
let result;
if (valueTemp == 'cel'){
result = celTofah(numberTemp);
document.getElementById('resultContainer').innerHTML = `= ${result}°Fahrenheit`
}
else if (valueTemp == 'fah'){
result = fahTocel(numberTemp);
document.getElementById('resultContainer').innerHTML = `= ${result}°Celsius`
}
}