-
Notifications
You must be signed in to change notification settings - Fork 0
/
bm.js
26 lines (22 loc) · 770 Bytes
/
bm.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
function calculateBMI() {
var weight = parseFloat(document.getElementById("weight").value);
var height = parseFloat(document.getElementById("height").value);
if (isNaN(weight) || isNaN(height)) {
alert("Please enter valid weight and height.");
return;
}
var bmi = weight / (height * height);
var bmiCategory = interpretBMI(bmi);
document.getElementById("result").innerHTML = "Your BMI is " + bmi.toFixed(2) + ". You are classified as: " + bmiCategory;
}
function interpretBMI(bmi) {
if (bmi < 18.5) {
return "Underweight";
} else if (bmi >= 18.5 && bmi < 25) {
return "Normal weight";
} else if (bmi >= 25 && bmi < 30) {
return "Overweight";
} else {
return "Obese";
}
}