-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
36 lines (33 loc) · 1.08 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
let celsius=document.querySelector("#Celsius");
let fahrenheit=document.querySelector("#Fahrenheit");
let kelvin=document.querySelector("#Kelvin");
let inp=document.querySelector("input");
// celsius.addEventListener("input",()=>{
// console.log(celsius.innerText);
// })
// console.log(kelvin.value);
// console.log(celsius.value);
// console.log(fahrenheit.value);
function ComputeTemp(event){
// console.log("change");
// console.log(event);
// console.log(event.target.name);
// console.log(event.target.value);
let currVal=+event.target.value; // add + sign to convert it into number
switch (event.target.name) {
case "Celsius":
fahrenheit.value=((currVal*1.8)+32).toFixed(2);
kelvin.value=(currVal+273.15).toFixed(2);
break;
case "Fahrenheit":
celsius.value=((currVal-32)/1.8).toFixed(2);
kelvin.value=((currVal-32)/1.8 + 273.15).toFixed(2);
break;
case "Kelvin":
celsius.value=(currVal-273.15).toFixed(2);
fahrenheit.value=(((currVal-273.15)*1.8)+32).toFixed(2);
break;
default:
break;
}
}