Skip to content

London | 26-ITP-Jan | Zadri Abdule | Sprint 3 | Alarm Clock app#1118

Open
Zadri415 wants to merge 2 commits intoCodeYourFuture:mainfrom
Zadri415:sprint-3/alarmclock
Open

London | 26-ITP-Jan | Zadri Abdule | Sprint 3 | Alarm Clock app#1118
Zadri415 wants to merge 2 commits intoCodeYourFuture:mainfrom
Zadri415:sprint-3/alarmclock

Conversation

@Zadri415
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

Added visual helpers: triggerVisualAlarm() and clearVisualAlarm()
Call triggerVisualAlarm() when the countdown reaches zero (and when a 0-second alarm is set)
Added a small load-time listener that attaches click handlers to the Set and Stop buttons to call clearVisualAlarm()

Questions

N/A

@Zadri415 Zadri415 added 📅 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 Mar 27, 2026
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan left a comment

Choose a reason for hiding this comment

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

Currently when starting a new countdown, the application does not always return to a clean initial state, which can lead to inconsistent behaviour between runs.

Note: a user may not click the "Stop" button first before starting a new count down.

Comment on lines +4 to +14
const m = Math.floor(remainingSeconds / 60);
const s = remainingSeconds % 60;
heading.textContent = `Time Remaining: ${pad(m)}:${pad(s)}`;
}
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.

For a "simple" function used locally in a function, we can define it as an arrow function in the function where it is used:

function updateHeading() {
  const pad = (n) => String(n).padStart(2, "0");

  ...
}

This way, we can keep only relatively key functions in the outermost scope.

@@ -1,5 +1,79 @@
function setAlarm() {}
let timerId = null;
let remainingSeconds = 0;
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.

Best practice is to avoid declaring variable in the global/outermost scope.
You can declare remainingSeconds as a local variable in setAlarm() and then pass it via a parameter to updateHeading().

Comment on lines +50 to +65
// Visual feedback helpers (add/remove a class on <body>)
function triggerVisualAlarm() {
try {
document.body.classList.add("alarm-active");
} catch (e) {
// ignore if DOM not available in test environment
}
}

function clearVisualAlarm() {
try {
document.body.classList.remove("alarm-active");
} catch (e) {
// ignore if DOM not available in test environment
}
}
Copy link
Copy Markdown
Contributor

@cjyuan cjyuan Apr 5, 2026

Choose a reason for hiding this comment

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

Nice touch in using a CSS class to manage animated background.

Could also consider combining this into one function and use a parameter to control whether to set or clear visual alarm, and set the default parameter value to "clear" or false.

@cjyuan cjyuan 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 Apr 5, 2026
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. Reviewed Volunteer to add when completing a review with trainee action still to take. 📅 Sprint 3 Assigned during Sprint 3 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants