function calculateRMR() {
var gender = document.getElementById("gender").value;
var weightKg = parseFloat(document.getElementById("weightKg").value);
var heightCm = parseFloat(document.getElementById("heightCm").value);
var ageYears = parseFloat(document.getElementById("ageYears").value);
var rmrCalories = 0;
if (isNaN(weightKg) || isNaN(heightCm) || isNaN(ageYears) || weightKg <= 0 || heightCm <= 0 || ageYears <= 0) {
document.getElementById("result").innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
if (gender === "male") {
rmrCalories = (10 * weightKg) + (6.25 * heightCm) – (5 * ageYears) + 5;
} else if (gender === "female") {
rmrCalories = (10 * weightKg) + (6.25 * heightCm) – (5 * ageYears) – 161;
}
document.getElementById("result").innerHTML =
"Your estimated Resting Metabolic Rate (RMR) is:
" + rmrCalories.toFixed(2) + " calories per day." +
"
This is the minimum number of calories your body needs to function at rest. Your total daily calorie needs will be higher based on your activity level.";
}
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
background-color: #fff;
}
.calculator-form h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-form p {
text-align: center;
margin-bottom: 30px;
color: #555;
line-height: 1.6;
}
.form-group {
margin-bottom: 15px;
display: flex;
align-items: center;
justify-content: space-between;
}
.form-group label {
flex-basis: 40%;
font-weight: bold;
color: #444;
}
.form-group input[type="number"],
.form-group select {
flex-basis: 55%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
.calculator-form button {
display: block;
width: 100%;
padding: 12px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-form button:hover {
background-color: #45a049;
}
.calculator-result {
margin-top: 30px;
padding: 15px;
border: 1px dashed #e0e0e0;
border-radius: 4px;
background-color: #f9f9f9;
text-align: center;
}
.calculator-result p {
margin-bottom: 10px;
color: #333;
}
.calculator-result strong {
color: #4CAF50;
}