Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -20,6 +55,8 @@ function playAlarm() {

function pauseAlarm() {
audio.pause();

clearInterval(alarmInterval);
}

window.onload = setup;
1 change: 1 addition & 0 deletions Sprint-3/alarmclock/alarmclock.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
<script src="alarmclock.js"></script>
</body>
</html>