Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
40 changes: 38 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
function setAlarm() {}
let timer;

function updateDisplay(time) {

let heading = document.getElementById("timeRemaining");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

None of these three are ever reassigned. What's your rule for picking between let and const?

@gideondefar gideondefar Aug 15, 2026

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.

Thanks for the feedback! ooh I see you are right. I use let basically to reassign the variable later but const is for fixed or constant variables.

let minutes = Math.floor(time / 60);
let seconds = time % 60;

heading.innerText =
"Time Remaining: " +
String(minutes).padStart(2, "0") +
":" +
String(seconds).padStart(2, "0");
}

function setAlarm() {

if (timer) clearInterval(timer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

In the browser, start a 10-second countdown, then clear the input box and click Set Alarm again. What happens to the countdown, and is that what a user would expect? Have a look at the order of this line and line 23.

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.

Now it keeps countdown to 0.

audio.pause();
audio.currentTime = 0;

let time = Number(document.getElementById("alarmSet").value);
if (isNaN(time) || !Number.isInteger(time) || time <= 0) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Run Number.isInteger(NaN) into your browser console and what comes back? Is the isNaN(time) check earning its place here?

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.

You are right, It's kind of redundant, So I removed it. !Number.isInteger(time) already checks the condition.


updateDisplay(time);

timer = setInterval(function () {
time = time - 1;

updateDisplay(time);

if (time <= 0) {
playAlarm();
clearInterval(timer);
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand All @@ -22,4 +58,4 @@ function pauseAlarm() {
audio.pause();
}

window.onload = setup;
window.onload = setup;
2 changes: 1 addition & 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 Down
Loading