-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (29 loc) · 840 Bytes
/
main.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
const btn = document.getElementById("calculate");
btn.addEventListener("click", function () {
let height = document.querySelector("#height").value;
let weight = document.querySelector("#weight").value;
if (height == "" || weight == "") {
alert("Please fill out the input fields!");
return;
}
height = height / 100;
let BMI = weight / (height * height);
BMI = BMI.toFixed(2);
document.querySelector("#result").innerHTML = BMI;
let status = "";
if (BMI < 18.5) {
status = "Underweight";
}
if (BMI >= 18.5 && BMI < 25) {
status = "Healthy";
}
if (BMI >= 25 && BMI < 30) {
status = "Overweight";
}
if (BMI >= 30) {
status = "Obese";
}
document.querySelector(
".comment"
).innerHTML = `Result: You are <span id="comment">${status}</span>`;
});