BMI Calculator
Understanding your Body Mass Index (BMI) is a common way to assess if your weight is healthy for your height. BMI is a measure derived from your weight and height. While it's a useful screening tool, it doesn't account for muscle mass, bone density, or body composition, so it's important to consult with a healthcare professional for a comprehensive health assessment.
Weight (kg):
Height (cm):
Calculate BMI
function calculateBMI() {
var weightInput = document.getElementById("weight");
var heightInput = document.getElementById("height");
var resultDiv = document.getElementById("result");
var bmiCategoryDiv = document.getElementById("bmi-category");
var weight = parseFloat(weightInput.value);
var height = parseFloat(heightInput.value);
if (isNaN(weight) || isNaN(height) || weight <= 0 || height <= 0) {
resultDiv.innerHTML = "Please enter valid positive numbers for weight and height.";
bmiCategoryDiv.innerHTML = "";
return;
}
// Convert height from cm to meters
var heightInMeters = height / 100;
// Calculate BMI: weight (kg) / [height (m)]^2
var bmi = weight / (heightInMeters * heightInMeters);
resultDiv.innerHTML = "Your BMI is: " + bmi.toFixed(2);
var category = "";
if (bmi = 18.5 && bmi = 25 && bmi < 29.9) {
category = "Overweight";
} else {
category = "Obesity";
}
bmiCategoryDiv.innerHTML = "BMI Category: " + category;
}
.calculator-container {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 400px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-container h2 {
text-align: center;
color: #333;
margin-bottom: 15px;
}
.calculator-container p {
text-align: justify;
color: #555;
margin-bottom: 20px;
line-height: 1.6;
}
.input-section {
margin-bottom: 15px;
}
.input-section label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.input-section input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
font-size: 1.1em;
font-weight: bold;
color: #333;
text-align: center;
}
#bmi-category {
margin-top: 10px;
font-size: 1em;
color: #666;
text-align: center;
}