Skip to content

London | 26-ITP-May | Eyob Zeray | Sprint 3 | alarmclock - #1316

Open
eyob-tech wants to merge 3 commits into
CodeYourFuture:mainfrom
eyob-tech:feature/alarmclock
Open

London | 26-ITP-May | Eyob Zeray | Sprint 3 | alarmclock#1316
eyob-tech wants to merge 3 commits into
CodeYourFuture:mainfrom
eyob-tech:feature/alarmclock

Conversation

@eyob-tech

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

Implemented setAlarm() in alarmclock.js so the app counts down from a
user-entered number of seconds, displays the remaining time in
#timeRemaining as MM:SS, and calls playAlarm() once it reaches zero.
Along the way, fixed a syntax error (missing backticks around template
literals) that was causing the whole script to fail to load and all 5 tests
to fail. All 5 tests in alarmclock.test.js now pass.

@eyob-tech eyob-tech added 🏕 Priority Mandatory This work is expected 📅 Sprint 3 Assigned during Sprint 3 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Data-Groups The name of the module. labels Jul 27, 2026

@Luro91 Luro91 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The title of the webpage should say Alarm clock app. It says Title here at the moment

Comment on lines +7 to +13
function updateDisplay() {
const minutes = Math.floor(secondsRemaining / 60);
const seconds = secondsRemaining % 60;
const paddedMinutes = String(minutes).padStart(2, "0");
const paddedSeconds = String(seconds).padStart(2, "0");
heading.innerText = `Time Remaining: ${paddedMinutes}:${paddedSeconds}`;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good job putting the code for formatting into an own function. This makes it reusable and easier to change the formatting if needed

const input = document.getElementById("alarmSet");
const heading = document.getElementById("timeRemaining");

let secondsRemaining = Number(input.value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if the number is 0 or negative?

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.

Good catch — I added a check right after reading the input to handle that. If the number's 0, negative, or not a real number at all, it just shows a message asking for a valid number and stops there instead of kicking off a countdown:

let secondsRemaining = Number(input.value);

if (!secondsRemaining || secondsRemaining <= 0) {
heading.innerText = "Please enter a number of seconds greater than 0";
return;
}

@@ -1,4 +1,29 @@
function setAlarm() {}
function setAlarm() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens when a user clicks the set alarm button multiple times?

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.

Ah good catch — turns out clicking it multiple times was starting a new countdown each time without stopping the old one, so they’d all run at once and mess with the display. I fixed it by keeping track of the current interval outside the function, and clearing it out before starting a fresh one whenever setAlarm() runs again:
let currentIntervalId = null;

function setAlarm() {
// ...validation, then:

if (currentIntervalId !== null) {
clearInterval(currentIntervalId);
}

currentIntervalId = setInterval(() => {
secondsRemaining--;
updateDisplay();

if (secondsRemaining <= 0) {
  clearInterval(currentIntervalId);
  currentIntervalId = null;
  playAlarm();
}

}, 1000);
}

@Luro91 Luro91 added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 30, 2026
@eyob-tech eyob-tech added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 30, 2026
@eyob-tech
eyob-tech requested a review from Luro91 July 30, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module-Data-Groups The name of the module. Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 🏕 Priority Mandatory This work is expected 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants