diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..36378d516 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,22 @@ -function setAlarm() {} +let alarmTimer; +function setAlarm() { + clearTimeout(alarmTimer); + let secondsRemaining = Number(document.getElementById("alarmSet").value); + function updateTimer() { + const minutes = Math.floor(secondsRemaining / 60); + const seconds = secondsRemaining % 60; + document.getElementById("timeRemaining").innerText = + `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; + if (secondsRemaining === 0) { + playAlarm(); + return; + } + secondsRemaining--; + alarmTimer = setTimeout(updateTimer, 1000); + } + updateTimer(); +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); @@ -22,4 +39,4 @@ function pauseAlarm() { audio.pause(); } -window.onload = setup; +window.onload = setup; \ No newline at end of file diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..4a91379d3 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App
diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..a5869c324 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -12,4 +12,4 @@ h1 { text-align: center; -} +} \ No newline at end of file