diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..45408e183 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,25 +1,60 @@ -function setAlarm() {} +let countdown; +let isPaused = false; +let timeRemaining; + +function setAlarm(){ + const inputField = document.getElementById("alarmSet"); + timeRemaining = parseInt(inputField.value); + + const updateTitle = () => { + const minutes = String(Math.floor(timeRemaining/60)).padStart(2, '0'); // minutes + const seconds = String(timeRemaining % 60).padStart(2, '0'); // seconds + document.getElementById("timeRemaining").innerText = `Time Remaining: ${minutes}:${seconds}`; + }; + + updateTitle(); + + countdown = setInterval(() => { + if (!isPaused){ + timeRemaining = timeRemaining - 1; + updateTitle(); + + if (timeRemaining <= 0) { + clearInterval(countdown); + playAlarm(); + } + } + }, 1000); +} + +function pauseTimer() { +isPaused = !isPaused; +document.getElementById("pause").innerText = isPaused ? "Resume Timer" : "Pause Timer"; +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); - function setup() { document.getElementById("set").addEventListener("click", () => { setAlarm(); }); - document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); }); + + document.getElementById("pause").addEventListener("click", () => { + pauseTimer(); + }); } function playAlarm() { audio.play(); } - function pauseAlarm() { audio.pause(); } - window.onload = setup; + + + diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..cfd3fdcb4 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ -