diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..d4ccb34ce 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,8 +1,30 @@ -function setAlarm() {} +var audio = new Audio("alarmsound.mp3"); -// DO NOT EDIT BELOW HERE +let countdown; -var audio = new Audio("alarmsound.mp3"); +function formatTime(seconds) { + let mins = Math.floor(seconds / 60); + let secs = seconds % 60; + return String(mins).padStart(2, "0") + ":" + String(secs).padStart(2, "0"); +} + +function setAlarm() { + let seconds = parseInt(document.getElementById("alarmSet").value); + clearInterval(countdown); + document.getElementById("timeRemaining").textContent = + "Time Remaining: " + formatTime(seconds); + + countdown = setInterval(() => { + seconds--; + document.getElementById("timeRemaining").textContent = + "Time Remaining: " + formatTime(seconds); + + if (seconds <= 0) { + clearInterval(countdown); + playAlarm(); + } + }, 1000); +} function setup() { document.getElementById("set").addEventListener("click", () => { @@ -19,6 +41,7 @@ function playAlarm() { } function pauseAlarm() { + clearInterval(countdown); audio.pause(); } diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..66748001e 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,10 +1,10 @@ - + - Title here + Alarm clock app