Heart Rate Zones Calculator

Heart Rate Zones Calculator

Determine your training zones based on your age.

Enter Your Details

Providing your resting heart rate (measured when you first wake up) will give a more personalized result using the Karvonen formula.

${maxHR} bpm

Calculated using: ${method}

`; // 2. Zones Table let zonesHtml = `
`; zones.forEach(zone => { zonesHtml += ` `; }); zonesHtml += `
Zone Intensity BPM Range
${zone.name.split(':')[0]} ${zone.intensity[0] * 100}% - ${zone.intensity[1] * 100}% ${zone.range}
`; resultsOutput.innerHTML = maxHrHtml + zonesHtml; resultsSection.classList.remove('hidden'); }; // --- 6. PDF GENERATION --- const handlePdfDownload = () => { const { jsPDF } = window.jspdf; const contentToPrint = document.getElementById('printable-content'); const buttonContainer = document.getElementById('pdf-button-container'); if (!contentToPrint) { console.error('Printable content not found.'); showError('Could not generate PDF. Please try again.'); return; } buttonContainer.classList.add('hide-for-pdf'); html2canvas(contentToPrint, { scale: 2, useCORS: true }).then(canvas => { buttonContainer.classList.remove('hide-for-pdf'); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / pdfWidth; const calculatedHeight = canvasHeight / ratio; const pdfHeight = pdf.internal.pageSize.getHeight(); let heightLeft = calculatedHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, calculatedHeight); heightLeft -= pdfHeight; while (heightLeft > 0) { position -= pdfHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, calculatedHeight); heightLeft -= pdfHeight; } pdf.save('Heart_Rate_Zones.pdf'); }).catch(err => { buttonContainer.classList.remove('hide-for-pdf'); console.error('PDF generation failed:', err); showError('An error occurred while generating the PDF.'); }); }; // --- 7. EVENT LISTENERS --- calculateBtn.addEventListener('click', calculateZones); downloadPdfBtn.addEventListener('click', handlePdfDownload); });
Scroll to Top