diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..0a18861f5 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,65 @@ -function setAlarm() {} +let intervalId; +let seconds; +let timeRemaining = document.getElementById("timeRemaining"); +let pause = false; +let setButton = document.getElementById("set"); +let pauseAndResumeButton = document.getElementById("pauseAndResume"); +let alarmInputField = document.getElementById("alarmInputField"); + +function calculateAndUpdate(seconds, timeRemaining) { + let mm = String(Math.floor(seconds / 60)).padStart(2, 0); + let ss = String(seconds % 60).padStart(2, 0); + timeRemaining.innerText = `Time Remaining: ${mm}:${ss}`; +} + +function countDown() { + intervalId = setInterval(() => { + seconds -= 1; + calculateAndUpdate(seconds, timeRemaining); + + if (seconds <= 0) { + clearInterval(intervalId); + playAlarm(); + document.body.classList.add("flash-background"); + pauseAndResumeButton.style.display = "none"; + } + }, 1000); +} + +function setAlarm() { + seconds = document.getElementById("alarmSet").value; + timeRemaining = document.getElementById("timeRemaining"); + + if (seconds > 0) { + calculateAndUpdate(seconds, timeRemaining); + setButton.style.display = "none"; + pauseAndResumeButton.style.display = "block"; + alarmInputField.style.display = "none"; + countDown(); + } +} + +document.getElementById("stop").addEventListener("click", () => { + document.body.classList.remove("flash-background"); + clearInterval(intervalId); + timeRemaining.innerText = `Time Remaining: 00:00`; + setButton.style.display = "block"; + pauseAndResumeButton.style.display = "none"; + alarmInputField.style.display = "block"; + pauseAndResumeButton.innerText = "Pause"; + pause = false; +}); + +document.getElementById("pauseAndResume").addEventListener("click", () => { + clearInterval(intervalId); + pause = !pause; + pause === true + ? (pauseAndResumeButton.innerText = "Resume") + : (pauseAndResumeButton.innerText = "Pause"); + if (pause === false) { + countDown(); + } +}); // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..2111accd1 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,16 +4,23 @@ - Title here + Alarm clock app

Time Remaining: 00:00

- - +
+ + +
- - +
+ + + +
diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..59a9c1353 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -4,6 +4,7 @@ left: 50%; -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%); + text-align: center; } #alarmSet { @@ -13,3 +14,49 @@ h1 { text-align: center; } + +@keyframes flash { + 0% { + background-color: silver; + color: white; + } + 50% { + background-color: white; + color: black; + } + 100% { + background-color: silver; + color: white; + } +} + +.flash-background { + animation: flash 1s infinite; +} + +#alarmInputField { + display: flex; + flex-direction: column; + text-align: center; + align-items: center; +} + +#alarmSet { + height: 30px; + max-width: 80px; + font-size: large; + text-align: center; +} + +#buttonField { + display: flex; + justify-content: space-evenly; + flex-wrap: wrap; + gap: 5px; +} + +button { + border-radius: 8px; + font-size: medium; + margin-top: 8px; +}