SimplySoundAdvice.com: What is your Body Mass Index (BMI)?
About this app
Calculate your Body Mass Index (BMI) using this simple tool.
SimplySoundAdvice.com: What is your Body Mass Index (BMI)? SimplySoundAdvice.com: What is your Body Mass Index (BMI)? Unit of Measurement: METRIC IMPERIAL Height (cm): Weight (kg): Calculate BMI Underweight: Less than 18.5 BMI Normal Weight: 18.5 to 24.9 BMI Overweight: 25 to 29.9 BMI Obese: 30 or more BMI Note: BMI is a useful measure for adults. It may not be accurate for athletes, elderly, or children.
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>SimplySoundAdvice.com: What is your Body Mass Index (BMI)?</title>
<meta name="description" content="Calculate your Body Mass Index (BMI) using this simple tool.">
<meta name="keywords" content="BMI, Body Mass Index, Health, Weight, Height, Calculator">
<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" rel="stylesheet">
<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.
// Constants
const METRIC = 'metric';
const IMPERIAL = 'imperial';
// Variables
let unit;
let height;
let weight;
// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Initialize user interface elements
const unitSelection = document.getElementById('unit-selection');
const heightContainer = document.getElementById('height-container');
const weightContainer = document.getElementById('weight-container');
const calculateButton = document.getElementById('calculate-button');
const bmiResult = document.getElementById('bmi-result');
const bmiLegend = document.getElementById('bmi-legend');
// Event listeners
unitSelection.addEventListener('change', handleUnitSelectionChange);
calculateButton.addEventListener('click', calculateBMI);
// Functions
function handleUnitSelectionChange(event) {
unit = event.target.value;
if (unit === METRIC) {
heightContainer.innerHTML = `
<label for="height">Height (cm):</label>
<input type="number" id="height" required>
`;
weightContainer.innerHTML = `
<label for="weight">Weight (kg):</label>
<input type="number" id="weight" required>
`;
} else if (unit === IMPERIAL) {
heightContainer.innerHTML = `
<label for="feet">Height (ft):</label>
<input type="number" id="feet" required>
<label for="inches">Height (in):</label>
<input type="number" id="inches" required>
`;
weightContainer.innerHTML = `
<label for="weight">Weight (lbs):</label>
<input type="number" id="weight" required>
`;
}
}
function calculateBMI() {
// Get user input values
if (unit === METRIC) {
height = parseInt(document.getElementById('height').value);
weight = parseInt(document.getElementById('weight').value);
} else if (unit === IMPERIAL) {
const feet = parseInt(document.getElementById('feet').value);
const inches = parseInt(document.getElementById('inches').value);
height = feet * 12 + inches;
weight = parseInt(document.getElementById('weight').value);
}
// Input validation
let error = false;
let errorMessage = '';
if (unit === METRIC) {
if (height < 140 || height > 210) {
error = true;
errorMessage += 'Height must be between 140 cm and 210 cm. ';
}
if (weight < 40 || weight > 200) {
error = true;
errorMessage += 'Weight must be between 40 kg and 200 kg. ';
}
} else if (unit === IMPERIAL) {
if (height < 55 || height > 83) {
error = true;
errorMessage += 'Height must be between 4\'7" (55 inches) and 6\'11" (83 inches). ';
}
if (weight < 88 || weight > 440) {
error = true;
errorMessage += 'Weight must be between 88 lbs and 440 lbs. ';
}
}
if (error) {
alert(errorMessage);
return;
}
// Calculate BMI
let bmi;
if (unit === METRIC) {
const heightInMeters = height / 100;
bmi = weight / (heightInMeters * heightInMeters);
} else if (unit === IMPERIAL) {
bmi = (weight / (height * height)) * 703;
}
// Display results
bmiResult.innerHTML = `
<h2>Your BMI: ${bmi.toFixed(1)}</h2>
`;
if (bmi < 18.5) {
bmiResult.style.color = 'blue';
bmiLegend.innerHTML = `
<div class="legend-item">
<div class="legend-circle" style="background-color: blue;"></div>
<div class="legend-label">Underweight: Less than 18.5 BMI</div>
</div>
`;
} else if (bmi >= 18.5 && bmi < 25) {
bmiResult.style.color = 'green';
bmiLegend.innerHTML = `
<div class="legend-item">
<div class="legend-circle" style="background-color: green;"></div>
<div class="legend-label">Normal Weight: 18.5 to 24.9 BMI</div>
</div>
`;
} else if (bmi >= 25 && bmi < 30) {
bmiResult.style.color = 'orange';
bmiLegend.innerHTML = `
<div class="legend-item">
<div class="legend-circle" style="background-color: orange;"></div>
<div class="legend-label">Overweight: 25 to 29.9 BMI</div>
</div>
`;
} else {
bmiResult.style.color = 'red';
bmiLegend.innerHTML = `
<div class="legend-item">
<div class="legend-circle" style="background-color: red;"></div>
<div class="legend-label">Obese: 30 or more BMI</div>
</div>
`;
}
}
});
} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>
<style>
body {
font-family: 'Roboto', sans-serif;
background-color: #f6f6f6;
}
h1 {
text-align: center;
margin-top: 20px;
margin-bottom: 30px;
color: #333;
font-size: 24px;
}
.container {
max-width: 500px;
margin: 0 auto;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input[type="number"] {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}
.btn-primary {
display: block;
width: 100%;
padding: 10px;
font-size: 16px;
color: #fff;
background-color: #007bff;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
.btn-primary:hover {
background-color: #0056b3;
}
#bmi-result {
text-align: center;
margin-bottom: 20px;
}
.legend-item {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.legend-circle {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 10px;
}
.legend-label {
color: #555;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>SimplySoundAdvice.com: What is your Body Mass Index (BMI)?</h1>
<div class="form-group">
<label for="unit-selection">Unit of Measurement:</label>
<select id="unit-selection">
<option value="metric">METRIC</option>
<option value="imperial">IMPERIAL</option>
</select>
</div>
<div id="height-container" class="form-group">
<label for="height">Height (cm):</label>
<input type="number" id="height" required>
</div>
<div id="weight-container" class="form-group">
<label for="weight">Weight (kg):</label>
<input type="number" id="weight" required>
</div>
<button id="calculate-button" class="btn-primary">Calculate BMI</button>
<div id="bmi-result"></div>
<div id="bmi-legend">
<div class="legend-item">
<div class="legend-circle" style="background-color: blue;"></div>
<div class="legend-label">Underweight: Less than 18.5 BMI</div>
</div>
<div class="legend-item">
<div class="legend-circle" style="background-color: green;"></div>
<div class="legend-label">Normal Weight: 18.5 to 24.9 BMI</div>
</div>
<div class="legend-item">
<div class="legend-circle" style="background-color: orange;"></div>
<div class="legend-label">Overweight: 25 to 29.9 BMI</div>
</div>
<div class="legend-item">
<div class="legend-circle" style="background-color: red;"></div>
<div class="legend-label">Obese: 30 or more BMI</div>
</div>
</div>
<p class="note">Note: BMI is a useful measure for adults. It may not be accurate for athletes, elderly, or children.</p>
</div>
</body>
</html>
NEW APPS
These are apps made by the community!