diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..0f7a1263e 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,36 @@ -function setAlarm() {} +function timeConvert(sec) { + let minutes = String(Math.floor(sec / 60)).padStart(2, "0"); + let seconds = String(sec % 60).padStart(2, "0"); + return `${minutes}:${seconds}`; +} + +let timer; +function setAlarm() { + clearInterval(timer); + pauseAlarm(); + + const timeInput = document.getElementById("alarmSet"); + let remainingSeconds = parseInt(timeInput.value); + if (isNaN(remainingSeconds) || remainingSeconds <= 0) { + alert("Please provide a valid number of seconds"); + return; + } + + timeInput.value = ""; + + const timeRemaining = document.getElementById("timeRemaining"); + + timeRemaining.textContent = `Time Remaining: ${timeConvert(remainingSeconds)}`; + + timer = setInterval(() => { + remainingSeconds--; + timeRemaining.textContent = `Time Remaining: ${timeConvert(remainingSeconds)}`; + if (remainingSeconds === 0) { + playAlarm(); + clearInterval(timer); + } + }, 1000); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..36715d7d9 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,23 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + Alarm clock app + + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + + \ No newline at end of file