diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..41e7a1708 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,39 @@ -function setAlarm() {} +let timer = null; + +function setAlarm() { + const input = document.getElementById("alarmSet"); + const heading = document.getElementById("timeRemaining"); + + let totalSeconds = Number(input.value); + + if (!input.value || totalSeconds <= 0) { + return; + } + + // stop previous timer + if (timer) { + clearInterval(timer); + } + + let minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0"); + let seconds = String(totalSeconds % 60).padStart(2, "0"); + + heading.innerText = `Time Remaining: ${minutes}:${seconds}`; + + timer = setInterval(() => { + totalSeconds--; + + let minutes = String(Math.floor(totalSeconds / 60)).padStart(2, "0"); + let seconds = String(totalSeconds % 60).padStart(2, "0"); + + heading.innerText = `Time Remaining: ${minutes}:${seconds}`; + + if (totalSeconds === 0) { + clearInterval(timer); + playAlarm(); + } + }, 1000); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..32964fb58 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -1,20 +1,24 @@ - - - - - Title here - - -
-

Time Remaining: 00:00

- - - - -
- - - + + + + + alarmclock.js + + + +
+

Time Remaining: 00:00

+ + + + + + +
+ + + + \ No newline at end of file diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..32b4c23a7 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -13,3 +13,7 @@ h1 { text-align: center; } + +body{ + background-color:darkgoldenrod; +} \ No newline at end of file