My Metabolic Rate Calculator
.metabolic-calc-container {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
max-width: 800px;
margin: 20px auto;
padding: 25px;
border: 1px solid #e0e0e0;
border-radius: 12px;
background-color: #ffffff;
box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}
.metabolic-calc-container h2 {
color: #2c3e50;
text-align: center;
margin-bottom: 25px;
font-size: 28px;
}
.calc-row {
display: flex;
flex-wrap: wrap;
gap: 20px;
margin-bottom: 15px;
}
.calc-group {
flex: 1;
min-width: 200px;
}
.calc-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #34495e;
}
.calc-group input, .calc-group select {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 16px;
box-sizing: border-box;
}
.calc-btn {
width: 100%;
background-color: #27ae60;
color: white;
padding: 15px;
border: none;
border-radius: 6px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
transition: background-color 0.3s;
margin-top: 10px;
}
.calc-btn:hover {
background-color: #219150;
}
.results-box {
margin-top: 30px;
padding: 20px;
background-color: #f9f9f9;
border-radius: 8px;
display: none;
}
.result-item {
display: flex;
justify-content: space-between;
padding: 10px 0;
border-bottom: 1px solid #eee;
}
.result-item:last-child {
border-bottom: none;
}
.result-label {
font-weight: 600;
color: #2c3e50;
}
.result-value {
font-weight: 700;
color: #27ae60;
font-size: 20px;
}
.article-section {
margin-top: 40px;
line-height: 1.6;
color: #333;
}
.article-section h3 {
color: #2c3e50;
margin-top: 25px;
}
.article-section p {
margin-bottom: 15px;
}
.activity-table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
.activity-table th, .activity-table td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
.activity-table th {
background-color: #f2f2f2;
}
function calculateMetabolism() {
var gender = document.getElementById("gender").value;
var age = parseFloat(document.getElementById("age").value);
var weight = parseFloat(document.getElementById("weight").value);
var height = parseFloat(document.getElementById("height").value);
var activity = parseFloat(document.getElementById("activity").value);
var bmr = 0;
if (!age || !weight || !height || age <= 0 || weight <= 0 || height <= 0) {
alert("Please enter valid positive numbers for age, weight, and height.");
return;
}
// Mifflin-St Jeor Equation
if (gender === "male") {
bmr = (10 * weight) + (6.25 * height) – (5 * age) + 5;
} else {
bmr = (10 * weight) + (6.25 * height) – (5 * age) – 161;
}
var tdee = bmr * activity;
document.getElementById("bmr-result").innerText = Math.round(bmr).toLocaleString() + " kcal/day";
document.getElementById("tdee-result").innerText = Math.round(tdee).toLocaleString() + " kcal/day";
document.getElementById("results").style.display = "block";
}