-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
28 lines (23 loc) · 837 Bytes
/
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
function calculateBMI() {
var heightInput = document.getElementById("height");
var weightInput = document.getElementById("weight");
var resultDiv = document.getElementById("result");
var height = parseFloat(heightInput.value);
var weight = parseFloat(weightInput.value);
if (isNaN(height) || isNaN(weight)) {
resultDiv.innerHTML = "Please enter valid height and weight.";
return;
}
var bmi = weight / ((height / 100) ** 2);
var category = "";
if (bmi < 18.5) {
category = "Underweight";
} else if (bmi < 25) {
category = "Normal weight";
} else if (bmi < 30) {
category = "Overweight";
} else {
category = "Obese";
}
resultDiv.innerHTML = "Your BMI is " + bmi.toFixed(2) + " (" + category + ")";
}