-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
26 lines (23 loc) · 854 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
const calculateTemp = () =>{
const inputTemp = document.getElementById('temp').value;
//console.log(numberTemp);
const tempSelected = document.getElementById('temp_diff');
const valueTemp = temp_diff.options[tempSelected .selectedIndex].value;
//console.log(valueTemp);
//Celsius to Fahrenheit
const celToFah = (cel) =>{
let fahrenheit = Math.round((cel* 9/5) +32).toFixed();
return fahrenheit;
}
//Fahrenheit to Celsius
const fahToCel = (fah) =>{
let celsius = Math.round((fah- 32)* 5/9);
return celsius;
}
if(valueTemp == 'cel'){
document.getElementById('resultContainer').innerHTML = celToFah(inputTemp) + "° Fahrenheit";
}
else{
document.getElementById('resultContainer').innerHTML= fahToCel(inputTemp) + "° Celcius";
}
}