The Body Mass Index (BMI) is a measure of body fat based on height and weight that applies to adult men and women. It's a common tool used to gauge whether your weight is healthy for your height.
Understanding Your BMI
Your Body Mass Index (BMI) is calculated using a simple formula: Weight (kg) / (Height (m) * Height (m)).
BMI Categories:
Underweight: Below 18.5
Normal weight: 18.5 – 24.9
Overweight: 25 – 29.9
Obesity: 30 or greater
It's important to remember that BMI is a screening tool and doesn't account for factors like muscle mass, bone density, or body composition. If you have concerns about your weight or health, consult a healthcare professional.
Example Calculation:
Let's say an individual weighs 75 kg and is 1.80 meters tall.
BMI = 75 kg / (1.80 m * 1.80 m)
BMI = 75 kg / 3.24 m²
BMI ≈ 23.15
Based on this BMI, the individual would fall into the "Normal weight" category.
function calculateBMI() {
var weightInput = document.getElementById("weight");
var heightInput = document.getElementById("height");
var resultDiv = document.getElementById("result");
var weight = parseFloat(weightInput.value);
var height = parseFloat(heightInput.value);
if (isNaN(weight) || isNaN(height) || height <= 0) {
resultDiv.innerHTML = "Please enter valid numbers for weight and height. Height must be greater than zero.";
return;
}
var bmi = weight / (height * height);
var bmiCategory = "";
if (bmi = 18.5 && bmi = 25 && bmi <= 29.9) {
bmiCategory = "Overweight";
} else {
bmiCategory = "Obesity";
}
resultDiv.innerHTML = "Your BMI is: " + bmi.toFixed(2) + "" +
"This falls into the category of: " + bmiCategory + "";
}
#bmi-calculator {
font-family: sans-serif;
max-width: 700px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-section {
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}
.explanation-section {
background-color: #fff;
padding: 15px;
border-radius: 5px;
border: 1px solid #ddd;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input[type="number"] {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
#result {
margin-top: 20px;
font-size: 18px;
}
#result strong {
color: #333;
}
.explanation-section h3, .explanation-section h4 {
margin-top: 0;
color: #555;
}
.explanation-section ul {
padding-left: 20px;
}
.explanation-section li {
margin-bottom: 8px;
}