-
Notifications
You must be signed in to change notification settings - Fork 966
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (33 loc) · 999 Bytes
/
app.js
File metadata and controls
40 lines (33 loc) · 999 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
30
31
32
33
34
35
36
37
38
39
40
const calculateBMI = () => {
const weight = weightInput.value;
const height = heightInput.value;
if (weight && height) {
// ✅ NEW VALIDATION (YOUR CONTRIBUTION)
if (weight <= 0 || height <= 0) {
bmiElement.innerHTML = '';
statusElement.innerHTML = '';
hideResults();
return;
}
const bmi = weight / (height ** 2);
if (isNaN(bmi)) {
hideResults();
return;
}
bmiElement.innerText = bmi.toFixed(2);
if (bmi < 18.5) {
statusElement.innerText = 'Underweight';
} else if (bmi < 25) {
statusElement.innerText = 'Normal';
} else if (bmi < 30) {
statusElement.innerText = 'Overweight';
} else {
statusElement.innerText = 'Obese';
}
showResults();
} else {
bmiElement.innerHTML = '';
statusElement.innerHTML = '';
hideResults();
}
}