Body Mass Index (BMI) is a measure that uses your height and weight to determine if your weight is healthy for your height. It's a common tool used by healthcare professionals to screen for weight categories that may lead to health problems.
The formula for BMI is:
BMI = weight (kg) / [height (m)]²
Alternatively, if you use imperial units:
BMI = [weight (lb) / (height (in))²] x 703
A higher BMI may indicate a higher percentage of body fat. Conversely, a lower BMI may indicate a lower percentage of body fat.
BMI Categories (WHO Standards):
Underweight: Below 18.5
Normal weight: 18.5 – 24.9
Overweight: 25 – 29.9
Obese: 30 or greater
Disclaimer: BMI is a screening tool and does not diagnose body fatness or individual health. Consult a healthcare professional for a comprehensive health assessment.
function calculateBMI() {
var heightCm = parseFloat(document.getElementById("heightCm").value);
var heightFt = parseFloat(document.getElementById("heightFt").value);
var heightIn = parseFloat(document.getElementById("heightIn").value);
var weightKg = parseFloat(document.getElementById("weightKg").value);
var weightLb = parseFloat(document.getElementById("weightLb").value);
var totalHeightM = 0;
var totalWeightKg = 0;
// Determine primary height input and convert to meters
if (!isNaN(heightCm) && heightCm > 0) {
totalHeightM = heightCm / 100;
} else if (!isNaN(heightFt) && !isNaN(heightIn) && (heightFt > 0 || heightIn > 0)) {
var totalHeightIn = (heightFt * 12) + heightIn;
totalHeightM = totalHeightIn * 0.0254;
} else {
document.getElementById("result").innerHTML = "Please enter a valid height.";
return;
}
// Determine primary weight input and convert to kilograms
if (!isNaN(weightKg) && weightKg > 0) {
totalWeightKg = weightKg;
} else if (!isNaN(weightLb) && weightLb > 0) {
totalWeightKg = weightLb * 0.453592;
} else {
document.getElementById("result").innerHTML = "Please enter a valid weight.";
return;
}
// Calculate BMI
var bmi = 0;
if (totalHeightM > 0) {
bmi = totalWeightKg / (totalHeightM * totalHeightM);
} else {
document.getElementById("result").innerHTML = "Invalid height entered.";
return;
}
bmi = bmi.toFixed(1); // Round to one decimal place
var category = "";
var categoryClass = "";
if (bmi = 18.5 && bmi = 25 && bmi = 30) {
category = "Obese";
categoryClass = "obese";
}
var resultHtml = "Your BMI is: " + bmi + "";
resultHtml += "This falls into the category: " + category + "";
document.getElementById("result").innerHTML = resultHtml;
}