function calculateRMR() {
var gender = document.getElementById("gender").value;
var weightKg = parseFloat(document.getElementById("weightKg").value);
var heightCm = parseFloat(document.getElementById("heightCm").value);
var age = parseFloat(document.getElementById("age").value);
var rmr = 0;
if (isNaN(weightKg) || isNaN(heightCm) || isNaN(age) || weightKg <= 0 || heightCm <= 0 || age <= 0) {
document.getElementById("result").innerHTML = "Please enter valid positive numbers for all fields.";
return;
}
if (gender === "male") {
// Mifflin-St Jeor Equation for Men
rmr = (10 * weightKg) + (6.25 * heightCm) – (5 * age) + 5;
} else {
// Mifflin-St Jeor Equation for Women
rmr = (10 * weightKg) + (6.25 * heightCm) – (5 * age) – 161;
}
document.getElementById("result").innerHTML =
"Your estimated Resting Metabolic Rate (RMR) is:" +
"" + rmr.toFixed(2) + " kcal/day" +
"This is the number of calories your body burns at rest each day. To determine your total daily energy expenditure (TDEE), you would multiply this RMR by an activity factor.";
}
.calculator-container {
font-family: Arial, sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 600px;
margin: 20px auto;
background-color: #f9f9f9;
}
.calculator-form h2 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
.calculator-form p {
text-align: center;
color: #555;
margin-bottom: 30px;
line-height: 1.6;
}
.form-group {
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 10px;
}
.form-group label {
flex: 1;
min-width: 100px; /* Ensure labels don't get too small */
font-weight: bold;
color: #444;
}
.form-group input[type="number"],
.form-group select {
flex: 2;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 20px;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 30px;
padding: 20px;
background-color: #e9ecef;
border: 1px solid #dee2e6;
border-radius: 5px;
text-align: center;
}
.calculator-result p {
margin: 10px 0;
color: #333;
}