Your maximum heart rate (MHR) is the highest number of times your heart can beat per minute during intense physical activity. It's a crucial metric for understanding your fitness level and designing effective workout plans. Several formulas can estimate MHR, with the most common and simplest being the Tanaka formula.
function calculateMaxHeartRate() {
var ageInput = document.getElementById("age");
var resultDiv = document.getElementById("result");
// Clear previous results
resultDiv.innerHTML = "";
// Input validation
var age = parseFloat(ageInput.value);
if (isNaN(age) || age <= 0) {
resultDiv.innerHTML = "Please enter a valid age greater than zero.";
return;
}
// Tanaka formula: MHR = 208 – (0.7 * Age)
var maxHeartRate = 208 – (0.7 * age);
// Display the result
resultDiv.innerHTML =
"Based on the Tanaka formula, your estimated maximum heart rate is:" +
"" + maxHeartRate.toFixed(0) + " beats per minute (bpm)" +
"This is an estimate, and your actual maximum heart rate may vary. It's recommended to consult with a healthcare professional or a certified fitness trainer for personalized guidance.";
}
.heart-rate-calculator {
font-family: sans-serif;
border: 1px solid #ccc;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
background-color: #f9f9f9;
}
.heart-rate-calculator h2 {
text-align: center;
margin-bottom: 20px;
color: #333;
}
.calculator-inputs {
display: flex;
flex-direction: column;
gap: 15px;
margin-bottom: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
.input-group input[type="number"] {
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1em;
}
.heart-rate-calculator button {
display: block;
width: 100%;
padding: 12px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 1.1em;
transition: background-color 0.3s ease;
}
.heart-rate-calculator button:hover {
background-color: #45a049;
}
.result-display {
margin-top: 20px;
padding: 15px;
background-color: #e0f2e9;
border: 1px solid #c8e6c9;
border-radius: 4px;
text-align: center;
}
.result-display p {
margin: 0 0 10px 0;
line-height: 1.5;
}
.result-display .calculation {
font-size: 1.3em;
color: #2e7d32;
}
.result-display .error {
color: #d32f2f;
font-weight: bold;
}