Expert-reviewed resources and digital tools designed to transform your body, mind, and energy levels.

Science-Based Weight Loss & Fitness Plans That Actually Work

Start Here-Best Fitness and Wellness Guides

Trending in Health & Nutrition

Expert-Back Health and Wellness Guides

HealthEndure Picks: Ebooks & Guides You’ll Love

Most Popular Weight Loss & Wellness Articles

Home Workout Plans & Exercise Guides

Join Healthendure

Download Your Free Moringa Guide

Signup & Unlock More Health Insights Straight to Your Inbox

0
document.addEventListener('DOMContentLoaded', function() { function calculateResults(isWakeup) { // Find inputs exactly as they are in your HTML snippets const inputId = isWakeup ? 'sleep-time-wake' : 'sleep-time-now'; const timeInput = document.getElementById(inputId); const ageInput = document.getElementById('sleep-age'); // From your age HTML if (!timeInput || !timeInput.value) { alert("Please select a time first!"); return; } const [hrs, mins] = timeInput.value.split(':'); let baseDate = new Date(); baseDate.setHours(parseInt(hrs), parseInt(mins), 0); // Best: 7.5h (5 cycles), Good: 6h (4 cycles), Min: 4.5h (3 cycles) const cycleHours = [7.5, 6, 4.5]; const targetIDs = ['time-best', 'time-good', 'time-min']; targetIDs.forEach((id, index) => { let resultDate = new Date(baseDate.getTime()); // 90 mins per cycle + 15 min buffer to fall asleep const totalMinutes = (cycleHours[index] * 60) + 15; const adjustment = isWakeup ? (totalMinutes * -1) : totalMinutes; resultDate.setMinutes(resultDate.getMinutes() + adjustment); const finalTime = resultDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: true }); const display = document.getElementById(id); if (display) { display.innerText = finalTime; } }); } // Attach listeners to your CSS IDs (btn-wake and btn-now) const wakeBtn = document.getElementById('btn-wake'); const nowBtn = document.getElementById('btn-now'); if (wakeBtn) { wakeBtn.addEventListener('click', function(e) { e.preventDefault(); // This STOPS the page jump calculateResults(true); }); } if (nowBtn) { nowBtn.addEventListener('click', function(e) { e.preventDefault(); // This STOPS the page jump calculateResults(false); }); } });