Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f988648
Update title tag in index.html
moses77-boop Nov 13, 2026
2de2f83
Add showTime function to display remaining time in alarm clock
moses77-boop Nov 13, 2026
253777f
Implement setAlarm function to retrieve and display remaining time
moses77-boop Nov 13, 2026
bdffa91
Fix setAlarm function to correctly update and display remaining time
moses77-boop Nov 13, 2026
2e305a0
Refactor setAlarm function to use a timerId variable for clearer inte…
moses77-boop Nov 13, 2026
3fca607
Fix setAlarm function to use the existing timerId variable for interv…
moses77-boop Nov 13, 2026
5da3f11
Add finished state styling for alarm clock background
moses77-boop Nov 13, 2026
39868bc
Fix formatting in setAlarm function
moses77-boop Nov 13, 2026
123f507
Add event listener to stop button to remove finished state
moses77-boop Nov 13, 2026
5821475
Remove finished state class at the start of setAlarm function
moses77-boop Nov 13, 2026
af537b5
Add animation to finished state background in CSS
moses77-boop Nov 13, 2026
1b2285a
Refactor flash keyframes for improved readability
moses77-boop Nov 13, 2026
94459aa
Remove background color from finished state in CSS
moses77-boop Nov 13, 2026
29d0c59
Add pause button to alarm clock interface
moses77-boop Nov 13, 2026
a7430b4
Refactor countdown logic to improve timer management and ensure consi…
moses77-boop Nov 13, 2026
dccac26
Refactor setAlarm function to streamline countdown logic and improve …
moses77-boop Nov 13, 2026
1c7f985
Add togglePause function to manage countdown state and update button …
moses77-boop Nov 13, 2026
261c9ca
Fix capitalization of "Pause" button text in togglePause function
moses77-boop Nov 13, 2026
7cd8c8c
Update pause button text to "Pause Alarm" in togglePause function
moses77-boop Nov 13, 2026
62a2056
Refactor code to set button text change in setAlarm function
moses77-boop Nov 16, 2026
9ca5ce2
Fix pause button text in togglePause function and ensure consistent f…
moses77-boop Nov 16, 2026
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
56 changes: 55 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
function setAlarm() {}
let timerId = null;
let remaining = 0;

function startCountdown() {
timerId = setInterval(() => {
remaining = remaining - 1;
showTime(remaining);

if (remaining <= 0) {
clearInterval(timerId);
timerId = null;
playAlarm();
document.body.classList.add("finished");
}
}, 1000);
}

function setAlarm() {
clearInterval(timerId);
document.body.classList.remove("finished");
document.getElementById("pause").innerText = "Pause Alarm";
remaining = Number(document.getElementById("alarmSet").value);
showTime(remaining);
startCountdown();
Comment on lines +20 to +24

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you pause a countdown and then press Set Alarm, what label does the pause button show while the new countdown is running?

To "like" or "dislike" this comment, please follow this link

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shows Resume and never changes back to Pause.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored my code for button text changes.

}

function showTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;

const mm = String(minutes).padStart(2, "0");
const ss = String(seconds).padStart(2, "0");

document.getElementById("timeRemaining").innerText =
`Time Remaining: ${mm}:${ss}`;
}

function togglePause() {
const pauseButton = document.getElementById("pause");

if (timerId !== null) {
clearInterval(timerId);
timerId = null;
pauseButton.innerText = "Resume Alarm";
} else if (remaining > 0) {
startCountdown();
pauseButton.innerText = "Pause Alarm";
}
}

document.getElementById("pause").addEventListener("click", togglePause);

document.getElementById("stop").addEventListener("click", () => {
document.body.classList.remove("finished");
});

// DO NOT EDIT BELOW HERE

Expand Down
5 changes: 3 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Alarm Clock app</title>
</head>
<body>
<div class="centre">
Expand All @@ -13,6 +13,7 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="pause" type="button">Pause Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
Expand Down
16 changes: 16 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@
h1 {
text-align: center;
}

body.finished {
animation: flash 1s infinite;
}

@keyframes flash {
0% {
background-color: white;
}
50% {
background-color: tomato;
}
100% {
background-color: white;
}
}