diff --git a/Sprint-3/alarmclock/Alarm clock app.html b/Sprint-3/alarmclock/Alarm clock app.html new file mode 100644 index 000000000..4a91379d3 --- /dev/null +++ b/Sprint-3/alarmclock/Alarm clock app.html @@ -0,0 +1,20 @@ + + + + + + + Alarm Clock App + + +
+

Time Remaining: 00:00

+ + + + + +
+ + + diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..c439c6a8a 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,45 @@ -function setAlarm() {} +let timeRemaining = 0; +let timer = null; + +function setAlarm() { + timeRemaining = document.getElementById("alarmSet").value; + + if (timeRemaining <= 0) { + alert("Enter a valid time in seconds!"); + return; + } + + updateTimeDisplay(); + + timer = setInterval(function () { + timeRemaining--; + updateTimeDisplay(); + + if (timeRemaining <= 0) { + clearInterval(timer); + document.body.style.backgroundColor = "red"; + playAlarm(); + } + }, 1000); +} + +function updateTimeDisplay() { + const minutes = Math.floor(timeRemaining / 60); + const seconds = timeRemaining % 60; + document.getElementById( + "timeRemaining" + ).innerText = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String( + seconds + ).padStart(2, "0")}`; +} + +function stopAlarmAndReset() { + clearInterval(timer); + timeRemaining = 0; + updateTimeDisplay(); + document.body.style.backgroundColor = ""; + pauseAlarm(); +} // DO NOT EDIT BELOW HERE diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..4a91379d3 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -4,7 +4,7 @@ - Title here + Alarm Clock App