Skip to content

Conversation

@asaniDev
Copy link

@asaniDev asaniDev commented Dec 8, 2025

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 functions to alarm to make the timer count down from input time and alarm to off when it reaches 0.

@asaniDev asaniDev added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. 📅 Sprint 3 Assigned during Sprint 3 of this module Module-Data-Groups The name of the module. labels Dec 8, 2025
@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 Dec 9, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 16, 2025
Comment on lines 17 to 20
if (timer) {
clearInterval(timer);
timer = null;
}
Copy link
Contributor

@cjyuan cjyuan Dec 16, 2025

Choose a reason for hiding this comment

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

You may also want to stop the alarm (to reset all application states before starting a new countdown)

Copy link
Author

Choose a reason for hiding this comment

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

added code to stop the alarm if it was playing

clearInterval(timer);
timer = null;
}
timer = setInterval(countDown, 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Line 20 will still get executed even when inputTime is 0.

Copy link
Author

Choose a reason for hiding this comment

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

removed redundant code

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 16, 2025
@asaniDev asaniDev added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 16, 2025
Comment on lines +11 to +30
if (inputTime === 10) {
changeBgColor = true;
} else if (inputTime === 0) {
displayTime(inputTime);
playAlarm();
document.querySelector("#alarmSet").reset();
}
displayTime(inputTime);
if (typeof audio !== "undefined" && audio) {
audio.pause();
try {
audio.currentTime = 0;
} catch (e) {}
audio.loop = false; // disable looping if it was set
}
if (timer) {
clearInterval(timer);
}
timer = setInterval(countDown, 1000);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When inputTime is 0, can you identify all the code between line 11 and 30 that will be executed? And among them, which code are unnecessarily executed?

Consider organising the code in the following maner:

  // Step 1: Reset everything (timer, audio, background, ...) before starting a new countdown
  // Note: Can also consider implement a function to reset everything and then call the function here
  ...
  
  // Step 2; Validate input
  ...
  
  // Step 3: Start a new countdown depending on the value of `inputTime`
  ...

@cjyuan cjyuan removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 17, 2025
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