-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (33 loc) · 1.22 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
let celsiusInput = document.querySelector('#celsius > input')
let fahrenheitInput = document.querySelector('#fahrenheit > input')
let kelvinInput = document.querySelector('#kelvin > input')
let btn = document.querySelector('.button button')
function roundNumber(number){
return Math.round(number*100)/100
}
celsiusInput.addEventListener('input', function(){
let cTemp = parseFloat(celsiusInput.value)
let fTemp = (cTemp*(9/5)) + 32
let kTemp = cTemp + 273.15
fahrenheitInput.value = roundNumber(fTemp)
kelvinInput.value = roundNumber(kTemp)
})
fahrenheitInput.addEventListener('input', function(){
let fTemp = parseFloat(fahrenheitInput.value)
let cTemp = (fTemp - 32) * (5/9)
let kTemp = (fTemp -32) * (5/9) + 273.15
celsiusInput.value = roundNumber(cTemp)
kelvinInput.value = roundNumber(kTemp)
})
kelvinInput.addEventListener('input', function(){
let kTemp = parseFloat(kelvinInput.value)
let cTemp = kTemp - 273.15
let fTemp = (kTemp - 273.15) * (9/5) + 32
celsiusInput.value = roundNumber(cTemp)
fahrenheitInput.value = roundNumber(fTemp)
})
btn.addEventListener('click', ()=>{
celsiusInput.value = ""
fahrenheitInput.value = ""
kelvinInput.value = ""
})