Your Target Heart Rate Zone
— bpm
function calculateHeartRate() {
var age = document.getElementById("age").value;
var intensity = document.getElementById("intensity").value;
var resultDiv = document.getElementById("targetHeartRate");
// Clear previous results
resultDiv.innerHTML = "– bpm";
// Validate inputs
if (age === "" || isNaN(age) || age <= 0) {
resultDiv.innerHTML = "Please enter a valid age.";
return;
}
// Calculate Maximum Heart Rate (MHR) using the common formula: 220 – age
var maxHeartRate = 220 – parseInt(age);
// Calculate Target Heart Rate (THR)
var targetHeartRate = maxHeartRate * (parseInt(intensity) / 100);
// Display the result
resultDiv.innerHTML = Math.round(targetHeartRate) + " bpm";
}
.calculator-wrapper {
font-family: sans-serif;
max-width: 600px;
margin: 20px auto;
padding: 20px;
border: 1px solid #e0e0e0;
border-radius: 8px;
background-color: #f9f9f9;
}
.calculator-form h2 {
text-align: center;
margin-bottom: 15px;
color: #333;
}
.calculator-form p {
margin-bottom: 20px;
color: #555;
line-height: 1.6;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #444;
}
.form-group input[type="number"],
.form-group select {
width: calc(100% – 22px);
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: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
.calculator-result {
margin-top: 25px;
padding: 15px;
border: 1px solid #d4edda;
border-radius: 4px;
background-color: #e9f7ef;
text-align: center;
}
.calculator-result h3 {
margin-top: 0;
color: #155724;
}
#targetHeartRate {
font-size: 24px;
font-weight: bold;
color: #28a745;
}