-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (26 loc) · 1.04 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
function weightConvert() {
const inputEl = document.querySelector(".weight-input").value;
let errorTime;
let resultTime;
if (inputEl <= 0 || isNaN(inputEl)) {
errorText = "Please enter a valid input";
const errorEl = document.querySelector(".error-line");
clearTimeout(errorTime);
errorTime = setTimeout(() => {
errorEl.innerText = "";
inputEl = "";
}, 2000);
errorEl.innerText = errorText;
} else {
let weightKG = 0;
weightKG = inputEl / 2.205;
const finalAnswerEl = document.querySelector(".final-answer");
finalAnswerEl.innerText = weightKG.toFixed(2);
clearTimeout(resultTime);
resultTime = setTimeout(() => {
finalAnswerEl.innerText = "";
inputEl = "";
}, 10000);
// the conversion result is only removed from the screen after ten seconds if the user does not enter a new input value during that time. If the user enters a new input value, the conversion result will remain on the screen until the next conversion is performed.
}
}