-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
40 lines (29 loc) · 1.17 KB
/
Copy pathscript.js
File metadata and controls
40 lines (29 loc) · 1.17 KB
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
function calculateBMI() {
const height = parseFloat(document.getElementById("height").value);
const weight = parseFloat(document.getElementById("weight").value);
const resultDiv = document.getElementById("result");
resultDiv.textContent = "";
if (isNaN(height) || isNaN(weight) || height <= 0 || weight <= 0) {
resultDiv.textContent = "Please enter valid, positive numbers.";
resultDiv.style.color = "red";
return;
}
const bmi = (weight / (height * height)).toFixed(2);
let status = "";
if (bmi < 18.5) {
status = "Underweight";
} else if (bmi < 25) {
status = "Normal";
} else if (bmi < 30) {
status = "Overweight";
} else {
status = "Obese";
}
resultDiv.style.color = "black";
resultDiv.innerHTML = `Your BMI is <strong>${bmi}</strong><br>Status: <strong>${status}</strong>`;
}
function resetForm() {
document.getElementById("height").value = "";
document.getElementById("weight").value = "";
document.getElementById("result").textContent = "";
}