-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
46 lines (37 loc) · 1.2 KB
/
script.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
let cal = document.querySelector("#calc");
const invalidMsg = () => {
let dis = document.querySelector(".result");
dis.innerHTML = "Inavlid Input";
dis.style.padding = "5px";
dis.style.fontSize = "20px";
dis.style.backgroundColor = "white";
dis.style.color = "green";
}
// const resetBtn=()=>{
// }
const calculateValue = (height, weight) => {
height = height / 100;
return Math.floor(weight / (Math.pow(height, 2)));
}
const showResult = (bmi) => {
let dis = document.querySelector(".result");
dis.innerHTML = `Bmi Score = ${bmi}`;
dis.style.padding = "5px";
dis.style.fontSize = "20px";
dis.style.backgroundColor = "white";
dis.style.color = "green";
}
cal.addEventListener("click", (e) => {
e.preventDefault();
let height = parseInt(document.querySelector("#height").value);
let weight = parseInt(document.querySelector("#weight").value);
console.log(height,weight);
if ((height === '' || height < 0 || isNaN(height)) && (weight=== '' || weight < 0 || isNaN(weight))) {
invalidMsg();
}
else {
let Bmi = calculateValue(parseInt(height), parseInt(weight));
showResult(Bmi);
}
// resetBtn();
});