-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (36 loc) · 1.37 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
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)
})
/*---------fahrenheit into celsius and kelvin---------*/
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)
})
/*---------kelvin into celsius and fahrenheit---------*/
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)
})
/*---------celsius into kelvin and fahrenheit---------*/
btn.addEventListener('click',()=>{
celsiusInput.value = ""
fahrenheitInput.value = ""
kelvinInput.value = ""
})