Your Heart Rate Zones:
Enter your age and resting heart rate (and optionally, your maximum heart rate) to see your zones.
function calculateHeartRateZones() {
var age = parseFloat(document.getElementById("age").value);
var restingHeartRate = parseFloat(document.getElementById("restingHeartRate").value);
var maxHeartRateInput = parseFloat(document.getElementById("maxHeartRate").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "; // Clear previous results
if (isNaN(age) || age <= 0) {
resultDiv.innerHTML = 'Please enter a valid age.';
return;
}
if (isNaN(restingHeartRate) || restingHeartRate <= 0) {
resultDiv.innerHTML = 'Please enter a valid resting heart rate.';
return;
}
var maxHeartRate;
if (isNaN(maxHeartRateInput) || maxHeartRateInput <= 0) {
// Estimate Max Heart Rate using the common formula: 220 – age
maxHeartRate = 220 – age;
if (maxHeartRate <= 0) { // Ensure maxHeartRate is positive
maxHeartRate = 190; // Fallback to a reasonable default if age is too high
}
} else {
maxHeartRate = maxHeartRateInput;
}
// Heart Rate Zones Calculation (common Apple Watch/Fitness Tracking approach)
// These zones are often expressed as a percentage of Maximum Heart Rate.
// Apple Watch typically uses:
// Zone 1: 50-60% of Max HR
// Zone 2: 60-70% of Max HR
// Zone 3: 70-80% of Max HR
// Zone 4: 80-90% of Max HR
// Zone 5: 90-100% of Max HR
var zones = {
"Zone 1 (Light)": { min: maxHeartRate * 0.50, max: maxHeartRate * 0.60 },
"Zone 2 (Moderate)": { min: maxHeartRate * 0.60, max: maxHeartRate * 0.70 },
"Zone 3 (Challenging)": { min: maxHeartRate * 0.70, max: maxHeartRate * 0.80 },
"Zone 4 (Hard)": { min: maxHeartRate * 0.80, max: maxHeartRate * 0.90 },
"Zone 5 (Maximum)": { min: maxHeartRate * 0.90, max: maxHeartRate * 1.00 }
};
var outputHTML = '
Estimated Maximum Heart Rate: ' + maxHeartRate.toFixed(0) + ' bpm';
outputHTML += '
';
for (var zoneName in zones) {
var minBpm = zones[zoneName].min;
var maxBpm = zones[zoneName].max;
outputHTML += '- ' + zoneName + ': ' + minBpm.toFixed(0) + ' – ' + maxBpm.toFixed(0) + ' bpm
';
}
outputHTML += '
';
resultDiv.innerHTML = outputHTML;
}
.calculator-container {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #f9f9f9;
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.calculator-input {
flex: 1;
min-width: 280px;
}
.calculator-output {
flex: 1;
min-width: 280px;
background-color: #fff;
padding: 15px;
border-radius: 5px;
border: 1px solid #eee;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #333;
}
.form-group input[type="number"] {
width: calc(100% – 12px);
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box; /* Include padding and border in the element's total width and height */
}
.calculator-input button {
background-color: #007bff;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
.calculator-input button:hover {
background-color: #0056b3;
}
#result p, #result li {
margin-bottom: 10px;
line-height: 1.5;
color: #555;
}
#result li {
list-style: disc;
margin-left: 20px;
}
#result strong {
color: #333;
}