diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..f61a114bf 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,35 @@ -function setAlarm() {} +let countdownInterval = null; + +function setAlarm() { + const timeInput = document.getElementById("alarmSet"); + let remainingTime = Number(timeInput.value); + + if (!timeInput.value || remainingTime <= 0) { + alert("Please set a valid time!"); + return; + } + + const timeRemainingDisplay = document.getElementById("timeRemaining"); + + if (countdownInterval !== null) { + clearInterval(countdownInterval); + } + + timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; + countdownInterval = setInterval(() => { + remainingTime -= 1; + if (remainingTime === 0) { + playAlarm(); + clearInterval(countdownInterval); + } + timeRemainingDisplay.innerText = `Time Remaining: ${formatTime(remainingTime)}`; + }, 1000); +} +function formatTime(seconds) { + const mm = String(Math.floor(seconds / 60)).padStart(2, "0"); + const ss = String(seconds % 60).padStart(2, "0"); + return `${mm}:${ss}`; +} // DO NOT EDIT BELOW HERE 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