-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
36 lines (29 loc) · 1.21 KB
/
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
29
30
31
32
33
34
35
36
document.addEventListener('DOMContentLoaded', function() {
const predictionForm = document.getElementById('predictionForm');
const resultContainer = document.getElementById('predictionResult');
// Hide the result container initially
resultContainer.style.display = 'none';
predictionForm.addEventListener('submit', function(event) {
event.preventDefault();
const age = document.getElementById('age').value;
const bmi = parseFloat(document.getElementById('bmi').value);
let resultText = '';
if (isNaN(bmi) || bmi <= 0) {
resultText = 'Invalid BMI';
} else if (bmi < 19) {
resultText = 'Underweight';
} else if (bmi >= 19 && bmi <= 24) {
resultText = 'Normal weight';
} else if (bmi >= 25 && bmi <= 29) {
resultText = 'Overweight';
} else if (bmi >= 30 && bmi <= 39) {
resultText = 'Obesity';
} else if (bmi >= 40) {
resultText = 'Severe obesity';
} else {
resultText = 'Invalid BMI';
}
resultContainer.innerHTML = `For age ${age}, your BMI indicates: ${resultText}`;
resultContainer.style.display = 'block'; // Show the result container
});
});