-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9_bmicalculator.html
More file actions
73 lines (64 loc) · 2.16 KB
/
Copy path9_bmicalculator.html
File metadata and controls
73 lines (64 loc) · 2.16 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
}
input {
padding: 8px;
margin: 5px;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<h1>BMI Calculator</h1>
<label for="weight">Weight (kg): </label>
<input type="number" id="weight" placeholder="Enter your weight"><br><br>
<label for="height">Height (cm): </label>
<input type="number"id="weight"placeholder="enter your height"><br><br>
<button onclick="calculateBMI()">Calculate BMI</button>
<div id="result"></div>
<script>
function calculateBMI() {
const weight = document.getElementById("weight").value;
const height = document.getElementById("height").value;
if (weight === "" || height === "") {
document.getElementById("result").innerHTML = "Please enter both weight and height.";
return;
}
const heightInMeters = height / 100; // Convert height to meters
const bmi = weight / (heightInMeters * heightInMeters);
let category = "";
if (bmi < 18.5) {
category = "Underweight";
} else if (bmi >= 18.5 && bmi < 24.9) {
category = "Normal weight";
} else if (bmi >= 25 && bmi < 29.9) {
category = "Overweight";
} else {
category = "Obese";
}
document.getElementById("result").innerHTML = `Your BMI is ${bmi.toFixed(2)}. Category: ${category}`;
}
</script>
</body>
</html>