diff --git a/Sprint-3/alarmclock/alarmclock.js b/Sprint-3/alarmclock/alarmclock.js index 6ca81cd3b..cdf7e0e85 100644 --- a/Sprint-3/alarmclock/alarmclock.js +++ b/Sprint-3/alarmclock/alarmclock.js @@ -1,4 +1,39 @@ -function setAlarm() {} +function setAlarm() { + //change the time remaining and set the remaining time + //into the second. + + let alarmInterval; + const InputField = document.querySelector("#alarmSet"); + let timeRemaining = InputField.value; + + function updateDisplay() { + const timedisplay = document.querySelector("#timeRemaining"); + const Minute = Math.floor(timeRemaining / 60); + const Second = timeRemaining % 60; + + const formatMinute = String(Minute).padStart(2, "0"); + const formatSecond = String(Second).padStart(2, "0"); + + timedisplay.innerText = `Time Remaining: ${formatMinute}:${formatSecond}`; + } + + updateDisplay(); + //set a variable to count three actions: + // count -1; + // Show what is the remaining time; + // if it goes to zero, beep the sound and stop the counting + + alarmInterval = setInterval(() => { + timeRemaining = timeRemaining - 1; + + updateDisplay(); + + if (timeRemaining === 0) { + playAlarm(); + clearInterval(alarmInterval); + } + }, 1000); +} // DO NOT EDIT BELOW HERE @@ -20,6 +55,8 @@ function playAlarm() { function pauseAlarm() { audio.pause(); + + clearInterval(alarmInterval); } window.onload = setup; diff --git a/Sprint-3/alarmclock/alarmclock.test.js b/Sprint-3/alarmclock/alarmclock.test.js index 85b7356dc..6fdfa258f 100644 --- a/Sprint-3/alarmclock/alarmclock.test.js +++ b/Sprint-3/alarmclock/alarmclock.test.js @@ -44,6 +44,7 @@ test("should set heading when button is clicked", () => { button.click(); expect(heading).toHaveTextContent("Time Remaining: 00:19"); + }); test("should split values over 60 seconds into minutes and seconds", () => { diff --git a/Sprint-3/alarmclock/index.html b/Sprint-3/alarmclock/index.html index 48e2e80d9..26a601edb 100644 --- a/Sprint-3/alarmclock/index.html +++ b/Sprint-3/alarmclock/index.html @@ -18,3 +18,9 @@