-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (24 loc) · 863 Bytes
/
Copy pathscript.js
File metadata and controls
29 lines (24 loc) · 863 Bytes
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
function BMICalculator() {
const weight = parseFloat(document.getElementById("weight").value);
const height = parseFloat(document.getElementById("height").value);
const bmiResult = document.getElementById("bmi");
const categoryResult = document.getElementById("category");
if (isNaN(weight) || isNaN(height) || weight <= 0 || height <= 0) {
bmiResult.textContent = "Please enter valid weight and height.";
categoryResult.textContent = "";
return;
}
const bmi = weight / (height * height);
let category = "";
if (bmi < 18.5) {
category = "Underweight";
} else if (bmi < 24.9) {
category = "Normal weight";
} else if (bmi < 29.9) {
category = "Overweight";
} else {
category = "Obesity";
}
bmiResult.textContent = `Your BMI is ${bmi.toFixed(2)}.`;
categoryResult.textContent = `You are ${category}.`;
}