diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..ec2622b4e 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,5 +1,41 @@ -function setAlarm() {} +let timeRemaining = 0; +let timerAlarm = null; +let timerPaused = false; +function setAlarm() { + const input = document.getElementById("alarmSet").value; + timeRemaining = parseInt(input, 10); + + if (!timeRemaining || timeRemaining <= 0) { + alert("Please only numbers above 0"); + return; + } + timerPaused = false; + updateDisplay(); + + if (timerAlarm) clearInterval(timerAlarm); + + timerAlarm = setInterval(() => { + if (!timerPaused) { + timeRemaining--; + console.log("Time left:", timeRemaining); + updateDisplay(); + + if (timeRemaining <= 0) { + clearInterval(timerAlarm); + playAlarm(); + } + } + }, 1000); +} + +function updateDisplay() { + const minutes = String(Math.floor(timeRemaining / 60)).padStart(2, "0"); + const seconds = String(timeRemaining % 60).padStart(2, "0"); + document.getElementById( + "timeRemaining" + ).innerText = `Time Remaining: ${minutes}: ${seconds}`; +} // DO NOT EDIT BELOW HERE var audio = new Audio("alarmsound.mp3"); @@ -8,18 +44,24 @@ function setup() { document.getElementById("set").addEventListener("click", () => { setAlarm(); }); - document.getElementById("stop").addEventListener("click", () => { pauseAlarm(); }); } +document.getElementById("pause").addEventListener("click", togglePause); function playAlarm() { audio.play(); + document.body.classList.add("flash"); } function pauseAlarm() { audio.pause(); + document.body.classList.remove("flash"); +} + +function togglePause() { + timerPaused = !timerPaused; } window.onload = setup; diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..104d7db18 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm clock App
@@ -14,6 +14,7 @@

Time Remaining: 00:00

+
diff --git a/Sprint-3/alarmclock/style.css b/Sprint-3/alarmclock/style.css index 0c72de38b..b27165d23 100644 --- a/Sprint-3/alarmclock/style.css +++ b/Sprint-3/alarmclock/style.css @@ -13,3 +13,12 @@ h1 { text-align: center; } +.flash { + animation: flash-bg 1s infinite; +} + +@keyframes flash-bg { + 0% {background-color: white;} + 50%{background-color: rgb(236, 160, 213);} + 100%{background-color: white;} +} \ No newline at end of file