diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..c980d1314 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,33 @@ -function setAlarm() {} +function setAlarm() { + const alarmSet = document.getElementById("alarmSet").value; + const timeRemaining = document.getElementById("timeRemaining"); + + let totalSeconds = parseInt(alarmSet); + + let countdown = setInterval(() => { + let minutes = Math.floor(totalSeconds / 60); + let seconds = totalSeconds % 60; + + timeRemaining.textContent = `Time Remaining: ${String( + minutes + ).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; + + if (totalSeconds <= 0) { + clearInterval(countdown); + playAlarm(); + let flash = setInterval(() => { + document.body.style.backgroundColor = + document.body.style.backgroundColor === "red" ? "white" : "red"; + }, 500); + setTimeout(() => { + clearInterval(flash); + document.body.style.backgroundColor = "white"; + }, 5000); + } + + totalSeconds--; + }, 1000); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..35cbbbe0e 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,16 +4,17 @@ - Title here + Alarm Clock App

Time Remaining: 00:00

- - - - + +
+ + +