-
Notifications
You must be signed in to change notification settings - Fork 0
/
ch10BMIpersistetdismissed.html
42 lines (37 loc) · 1.18 KB
/
ch10BMIpersistetdismissed.html
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
41
42
<!DOCTYPE html>
<html>
<head>
<title>BMI Calculator</title>
<script>
function calculateBMI() {
// retrieve user input for weight and height
var weight = document.getElementById("weight").value;
var height = document.getElementById("height").value;
// calculate BMI using the formula
var bmi = weight / (height * height);
// display the calculated BMI on a new web page
document.write("<h2>Your BMI is: " + bmi.toFixed(2) + "</h2>");
// provide feedback to the user based on their BMI
if (bmi < 18.5) {
document.write("<p>You are underweight.</p>");
} else if (bmi >= 18.5 && bmi < 25) {
document.write("<p>You are at a healthy weight.</p>");
} else if (bmi >= 25 && bmi < 30) {
document.write("<p>You are overweight.</p>");
} else {
document.write("<p>You are obese.</p>");
}
}
</script>
</head>
<body>
<h1>BMI Calculator</h1>
<form>
<label for="weight">Weight (kg):</label>
<input type="number" id="weight" name="weight" required>
<label for="height">Height (m):</label>
<input type="number" id="height" name="height" step="0.01" required>
<input type="button" value="Calculate BMI" onclick="calculateBMI()">
</form>
</body>
</html>