-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbmicalculator.html
65 lines (58 loc) · 1.97 KB
/
bmicalculator.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<title>BMI Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
#calculator {
background-color: #f5f5f5;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
}
#result {
font-weight: bold;
}
</style>
</head>
<body>
<div id="calculator">
<h1>BMI Calculator</h1>
<label for="weight">Weight (kg):</label>
<input type="number" id="weight" placeholder="Enter your weight" required><br><br>
<label for="height">Height (cm):</label>
<input type="number" id="height" placeholder="Enter your height" required><br><br>
<button onclick="calculateBMI()">Calculate BMI</button><br><br>
<div id="result"></div>
</div>
<script>
function calculateBMI() {
var weight = parseFloat(document.getElementById('weight').value);
var height = parseFloat(document.getElementById('height').value);
if (isNaN(weight) || isNaN(height) || weight <= 0 || height <= 0) {
document.getElementById('result').innerHTML = "Please enter valid weight and height.";
return;
}
var bmi = weight / ((height / 100) ** 2);
var category;
if (bmi < 18.5) {
category = "Underweight";
} else if (bmi < 24.9) {
category = "Normal Weight";
} else if (bmi < 29.9) {
category = "Overweight";
} else {
category = "Obese";
}
document.getElementById('result').innerHTML = "Your BMI is " + bmi.toFixed(2) + " (" + category + ")";
}
</script>
</body>
</html>