-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
32 lines (26 loc) · 878 Bytes
/
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
let celsius = document.getElementById("celsius");
let fahrenheit = document.getElementById("fahrenheit");
celsius.addEventListener('input', function () {
// getting user input
let cel = this.value;
// finding fahrenheit value using below formula
let fah = (cel * 9 / 5) + 32;
// after decimal, we need till 4 digit
if (!Number.isInteger(fah)) {
fah = fah.toFixed(4);
}
// updating value in fahrenheut box
fahrenheit.value = fah;
})
fahrenheit.addEventListener('input', function () {
// getting user input
let fah = this.value;
// finding celsius value using below formula
let cel = (fah - 32) * 5 / 9;
// after decimal, we need till 4 digit
if (!Number.isInteger(cel)) {
cel = cel.toFixed(4);
}
// updating value in celsius box
celsius.value = cel;
})