diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..c5be86732 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,27 @@ -function setAlarm() {} +const title = document.querySelector('title') +title.textContent = "Alarm clock app"; +function time_convert(num) { + let minutes = Math.floor((num % 3600) / 60); + let seconds = num % 60; + return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0'); +} +function setAlarm() { + const alarmSetInputEl = document.getElementById("alarmSet"); + let timeEl = Number(alarmSetInputEl.value); + const timeRemainingCounterEl = document.getElementById("timeRemaining"); + const interval = setInterval(() => { + timeEl--; + + timeRemainingCounterEl.textContent = `Time Remaining: ${time_convert(timeEl)}`; + + if (timeEl <= 0) { + clearInterval(interval); + timeRemainingCounterEl.textContent = "Done!"; + playAlarm(); + } + }, 1000); +} + // DO NOT EDIT BELOW HERE @@ -23,3 +46,4 @@ function pauseAlarm() { } window.onload = setup; + diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..d74c5a886 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -18,3 +18,4 @@

Time Remaining: 00:00

+