-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (37 loc) · 1.42 KB
/
app.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
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;
}
/*Celsius to fahrenheit and Kelvin*/
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 to 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 to Celsius and Fahrenheit */
kelvinInput.addEventListener("input", function(){
let kTemp = parseFloat(kelvinInput.value);
let fTemp = (kTemp - 273.15)*(9/5) + 32
let cTemp = (kTemp - 273.15)
celsiusInput.value = roundNumber(cTemp);
fahrenheitInput.value = roundNumber(fTemp);
});
/* clear button */
btn.addEventListener("click", function(){
celsiusInput.value = ""
fahrenheitInput.value = ""
kelvinInput.value = ""
})