What is your Body Mass Index (BMI)?
About this app
Calculate your Body Mass Index (BMI) and find out if you are underweight, normal weight, overweight, or obese.
What is your Body Mass Index (BMI)? What is your Body Mass Index (BMI)? Unit of Measurement METRIC IMPERIAL Height (cm) Weight (kg) Height (ft) Height (in) Weight (lbs) Calculate BMI Your BMI: Underweight Normal Weight Overweight Obese BMI is a useful measure for adults. It may not be accurate for athletes, elderly, or children. Calculate Again
Related apps
Put this on your site
Source
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>What is your Body Mass Index (BMI)?</title>
<meta name="description" content="Calculate your Body Mass Index (BMI) and find out if you are underweight, normal weight, overweight, or obese.">
<meta name="keywords" content="BMI calculator, body mass index, weight, height, underweight, normal weight, overweight, obese">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Initialize user interface elements
const unitSelector = document.getElementById('unitSelector');
const metricContainer = document.getElementById('metricContainer');
const imperialContainer = document.getElementById('imperialContainer');
const heightCmInput = document.getElementById('heightCmInput');
const weightKgInput = document.getElementById('weightKgInput');
const heightFtInput = document.getElementById('heightFtInput');
const heightInInput = document.getElementById('heightInInput');
const weightLbsInput = document.getElementById('weightLbsInput');
const calculateBtn = document.getElementById('calculateBtn');
const resultContainer = document.getElementById('resultContainer');
const bmiValue = document.getElementById('bmiValue');
const bmiCategory = document.getElementById('bmiCategory');
const legendContainer = document.getElementById('legendContainer');
const noteContainer = document.getElementById('noteContainer');
const restartBtn = document.getElementById('restartBtn');
// Add event listeners
unitSelector.addEventListener('change', handleUnitChange);
calculateBtn.addEventListener('click', calculateBMI);
restartBtn.addEventListener('click', restartCalculator);
// Function to handle unit change
function handleUnitChange() {
const selectedUnit = unitSelector.value;
if (selectedUnit === 'metric') {
metricContainer.style.display = 'block';
imperialContainer.style.display = 'none';
} else {
metricContainer.style.display = 'none';
imperialContainer.style.display = 'block';
}
resultContainer.style.display = 'none';
noteContainer.style.display = 'none';
restartBtn.style.display = 'none';
}
// Function to calculate BMI
function calculateBMI() {
const selectedUnit = unitSelector.value;
if (selectedUnit === 'metric') {
const heightCm = Number(heightCmInput.value);
const weightKg = Number(weightKgInput.value);
if (isNaN(heightCm) || isNaN(weightKg) || heightCm <= 0 || weightKg <= 0) {
alert('Please enter valid height and weight values.');
return;
}
const heightM = heightCm / 100;
const bmi = weightKg / (heightM * heightM);
displayResult(bmi);
} else {
const heightFt = Number(heightFtInput.value);
const heightIn = Number(heightInInput.value);
const weightLbs = Number(weightLbsInput.value);
if (isNaN(heightFt) || isNaN(heightIn) || isNaN(weightLbs) || heightFt < 0 || heightIn < 0 || weightLbs <= 0) {
alert('Please enter valid height and weight values.');
return;
}
const heightInches = heightFt * 12 + heightIn;
const bmi = (weightLbs / (heightInches * heightInches)) * 703;
displayResult(bmi);
}
}
// Function to display BMI result
function displayResult(bmi) {
resultContainer.style.display = 'block';
bmiValue.textContent = bmi.toFixed(1);
if (bmi < 18.5) {
bmiCategory.textContent = 'Underweight';
bmiCategory.style.color = 'blue';
} else if (bmi >= 18.5 && bmi <= 24.9) {
bmiCategory.textContent = 'Normal Weight';
bmiCategory.style.color = 'green';
} else if (bmi >= 25 && bmi <= 29.9) {
bmiCategory.textContent = 'Overweight';
bmiCategory.style.color = 'orange';
} else {
bmiCategory.textContent = 'Obese';
bmiCategory.style.color = 'red';
}
legendContainer.style.display = 'block';
noteContainer.style.display = 'block';
restartBtn.style.display = 'block';
}
// Function to restart calculator
function restartCalculator() {
unitSelector.value = 'metric';
handleUnitChange();
}
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
/* App CSS Goes Here */
body {
font-family: 'Roboto', Arial, sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
font-weight: 700;
margin-bottom: 5px;
color: #333;
}
.form-group input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
.btn {
display: block;
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background-color: #333;
color: #fff;
font-size: 16px;
text-align: center;
cursor: pointer;
transition: background-color 0.3s ease;
}
.btn:hover {
background-color: #555;
}
.result-container {
margin-top: 20px;
display: none;
}
.result-container h2 {
text-align: center;
margin-bottom: 10px;
color: #333;
}
.result-container p {
text-align: center;
margin-bottom: 10px;
font-size: 24px;
}
.legend-container {
margin-top: 20px;
display: none;
text-align: center;
}
.legend-item {
display: inline-block;
margin-right: 10px;
}
.legend-circle {
display: inline-block;
width: 16px;
height: 16px;
border-radius: 50%;
margin-right: 5px;
}
.legend-text {
display: inline-block;
font-weight: 700;
}
.note-container {
margin-top: 20px;
display: none;
text-align: center;
color: #999;
}
.restart-btn {
margin-top: 20px;
display: none;
text-align: center;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>What is your Body Mass Index (BMI)?</h1>
<div class="form-group">
<label for="unitSelector">Unit of Measurement</label>
<select id="unitSelector">
<option value="metric">METRIC</option>
<option value="imperial">IMPERIAL</option>
</select>
</div>
<div id="metricContainer">
<div class="form-group">
<label for="heightCmInput">Height (cm)</label>
<input type="number" id="heightCmInput" placeholder="Enter height in cm">
</div>
<div class="form-group">
<label for="weightKgInput">Weight (kg)</label>
<input type="number" id="weightKgInput" placeholder="Enter weight in kg">
</div>
</div>
<div id="imperialContainer" style="display: none;">
<div class="form-group">
<label for="heightFtInput">Height (ft)</label>
<input type="number" id="heightFtInput" placeholder="Enter height in ft">
</div>
<div class="form-group">
<label for="heightInInput">Height (in)</label>
<input type="number" id="heightInInput" placeholder="Enter height in in">
</div>
<div class="form-group">
<label for="weightLbsInput">Weight (lbs)</label>
<input type="number" id="weightLbsInput" placeholder="Enter weight in lbs">
</div>
</div>
<button id="calculateBtn" class="btn">Calculate BMI</button>
<div id="resultContainer" class="result-container">
<h2>Your BMI:</h2>
<p id="bmiValue"></p>
<p id="bmiCategory"></p>
</div>
<div id="legendContainer" class="legend-container">
<div class="legend-item">
<span class="legend-circle" style="background-color: blue;"></span>
<span class="legend-text">Underweight</span>
</div>
<div class="legend-item">
<span class="legend-circle" style="background-color: green;"></span>
<span class="legend-text">Normal Weight</span>
</div>
<div class="legend-item">
<span class="legend-circle" style="background-color: orange;"></span>
<span class="legend-text">Overweight</span>
</div>
<div class="legend-item">
<span class="legend-circle" style="background-color: red;"></span>
<span class="legend-text">Obese</span>
</div>
</div>
<div id="noteContainer" class="note-container">
<p>BMI is a useful measure for adults. It may not be accurate for athletes, elderly, or children.</p>
</div>
<div id="restartBtn" class="restart-btn">
<button class="btn">Calculate Again</button>
</div>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!