Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb0ec17
updated the Title of alarm clock template file
Tobias-Amaechina Jul 28, 2026
b45f3d2
Created a global varible to hold remaining time and the interval id
Tobias-Amaechina Jul 28, 2026
4e3b1d2
implement a function that set the alarm
Tobias-Amaechina Jul 28, 2026
51dfb2e
Implements function to display updates on the page
Tobias-Amaechina Jul 28, 2026
55ab312
Implement a function that stops the alarm
Tobias-Amaechina Jul 28, 2026
e418ebc
set alarm button and add event listener
Tobias-Amaechina Jul 28, 2026
6a0c87e
add stop alarm button and add event listener
Tobias-Amaechina Jul 28, 2026
7b7a44a
updated the wrong name variable in the input variable and Title vari…
Tobias-Amaechina Jul 28, 2026
84985a9
removed the broken event listeners
Tobias-Amaechina Jul 28, 2026
dfa54e5
Add Node to interact with the styling document
Tobias-Amaechina Jul 28, 2026
6208876
declate a booleen varaible an set to false
Tobias-Amaechina Jul 28, 2026
7e08577
add a pause button element in the template
Tobias-Amaechina Jul 28, 2026
d4458e2
deleted broken functions and updated Id pause name
Tobias-Amaechina Jul 28, 2026
4c8eeb9
added into the set alarm function A note for flashing
Tobias-Amaechina Jul 28, 2026
67ca5df
Add event listener to stop the flash
Tobias-Amaechina Jul 28, 2026
0496416
created a global variable to toggle pause an set it to false
Tobias-Amaechina Jul 28, 2026
b2b7638
created a function to toggle and pause
Tobias-Amaechina Jul 28, 2026
df1b2f4
wire the pause button to togglepause
Tobias-Amaechina Jul 28, 2026
5896a93
updated the style sheet to have the animation
Tobias-Amaechina Jul 28, 2026
a940501
changed the Title in the template as Alarm clock app
Tobias-Amaechina Jul 28, 2026
3a4bb35
Create a newfunction startCountdown and remove the duplicated code
Tobias-Amaechina Aug 5, 2026
6a5d331
clears time with intervalId to null
Tobias-Amaechina Aug 5, 2026
f9ad3be
created a check to check if intervalId is null
Tobias-Amaechina Aug 5, 2026
f057c76
Created logical AND to check for finshsed timer
Tobias-Amaechina Aug 5, 2026
80d4b45
Trimm empty spaces
Tobias-Amaechina Aug 5, 2026
c283013
wrote a statement to check for empty input
Tobias-Amaechina Aug 5, 2026
cad0b79
wrote a tatement to validate that the input is a positive number and…
Tobias-Amaechina Aug 5, 2026
7740b88
Wrote a statement for stronger validation . added a reset function …
Tobias-Amaechina Aug 5, 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
96 changes: 95 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,98 @@
function setAlarm() {}
let timeRemaining = 0;
let intervalId = null;
let isPaused = false;

function reset() {
// 1. Stop any active interval timer and clear the ID
clearInterval(intervalId);
intervalId = null;

// 2. Reset the state variables back to default
timeRemaining = 0;
isPaused = false;

// 3. Stop visual and audio effects
document.body.classList.remove("flash");
pauseAlarm();

// 4. Update the screen display back to 00:00
updateDisplay(0);
}

function setAlarm() {
const input = document.getElementById("alarmSet");
const value = input.value.trim();//trim empty string
//Check if the input is empty
if (value === "") {
Comment on lines +24 to +26

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code is clear and readable enough. I don't think these comments could make the code any clearer.

alert("Please enter a number of seconds.");
return;
}

const seconds = Number(value);
//validate that input is a positive integer and doestn't exceed 1 hour
if (
isNaN(seconds) ||
!Number.isInteger(seconds) ||
Comment on lines +34 to +35

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One of these checks is redundant.

seconds <= 0 ||
seconds > 3600
) {
alert("Please enter a valid whole number between 1 and 3600.");
return;
}
reset();

timeRemaining = seconds;
isPaused = false;
updateDisplay(timeRemaining);
// Start a new countdown
startCountdown();
Comment on lines +47 to +48

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is probably not needed.

}

function startCountdown() {
if (intervalId !== null) {
return;
}
Comment thread
cjyuan marked this conversation as resolved.

intervalId = setInterval(() => {
timeRemaining--;
updateDisplay(timeRemaining);

if (timeRemaining <= 0) {
clearInterval(intervalId);
intervalId = null;
playAlarm();
document.body.classList.add("flash");
}
}, 1000);
}

function updateDisplay(seconds) {
const title = document.getElementById("timeRemaining");


const mins = String(Math.floor(seconds / 60)).padStart(2, "0");
const secs = String(seconds % 60).padStart(2, "0");

title.textContent = `Time Remaining: ${mins}:${secs}`;
}
function togglePause() {
if (intervalId === null && !isPaused) {
return;
}

if (!isPaused) {
clearInterval(intervalId);
intervalId = null;
isPaused = true;
} else {
isPaused = false;
startCountdown();
}
}
document.getElementById("pause").addEventListener("click", togglePause);
document.getElementById("stop").addEventListener("click", reset);



// DO NOT EDIT BELOW HERE

Expand Down
4 changes: 3 additions & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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 @@ -14,6 +14,8 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
<button id="pause">Pause</button>

</div>
<script src="alarmclock.js"></script>
</body>
Expand Down
8 changes: 8 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@
h1 {
text-align: center;
}
.flash {
animation: flash-bg 0.5s infinite alternate;
}

@keyframes flash-bg {
from { background-color: white; }
to { background-color: red; }
}
Loading