Skip to content

London|26-ITP-January|Alexandru Pocovnicu|Sprint 3| alarm clock#1057

Open
alexandru-pocovnicu wants to merge 25 commits intoCodeYourFuture:mainfrom
alexandru-pocovnicu:sprint-3-alarm-clock
Open

London|26-ITP-January|Alexandru Pocovnicu|Sprint 3| alarm clock#1057
alexandru-pocovnicu wants to merge 25 commits intoCodeYourFuture:mainfrom
alexandru-pocovnicu:sprint-3-alarm-clock

Conversation

@alexandru-pocovnicu
Copy link
Copy Markdown

@alexandru-pocovnicu alexandru-pocovnicu commented Mar 20, 2026

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 an alarm clock that counts down from the input value

@alexandru-pocovnicu alexandru-pocovnicu added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Mar 20, 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.

Code works fine if a user only clicks the "Set Alarm" button once.
However, if the user enters a time and then clicks the "Set Alarm" button multiple times, the countdown clock will not display properly.
Can you fix the issue?


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.

Consider introducing a dedicated reset function to return the app to a clean initial state to help ensure consistency.

@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 Mar 30, 2026
@alexandru-pocovnicu
Copy link
Copy Markdown
Author

when i press stopalarm i want the countdown to go to 0,call pauseAlarm(), and the class to be removed from the body,but on line 48 i have this message // DO NOT EDIT BELOW HERE, I can't really think of a way of doing it without adding code bellow that

@alexandru-pocovnicu alexandru-pocovnicu 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 Apr 3, 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.

Note: To reset countdown display when the user clicks "Stop", and without modifying existing code, you can add another event listener to the stop button:

  document.getElementById("stop").addEventListener("click", () => {
    // Your code here ...
  });

let paddedSeconds = seconds.toString().padStart(2, "0");
let paddedMinutes = minutes.toString().padStart(2, "0");
timeRemainingEl.innerHTML = `Time Remaining: ${paddedMinutes}:${paddedSeconds}`;
alarmSetEl.value = null;
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.

Why clear the input field when updating the timer display? When a countdown is active, it will be cleared every second.

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.

didn't realise it was doing it every second , now there is a dedicated function to clear everything when the alarm is set

@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 3, 2026
Comment on lines +6 to +11
const pauseButton = document.getElementById("pause-button");
if (pauseButton) {
pauseButton.removeAttribute("id");
pauseButton.classList.add("unpause-alarm");
pauseButton.addEventListener("click", pauseCountDown);
}
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 is an unusual way to perform the tasks once (or to make the pause button visible when the "Start alarm" button is clicked the first time). Why not perform the task once on page load?

Currently unpause-alarm class does not have any style defined in style.css. (Work in progress?)

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.

i was thinking to use it , since i was removing the id I needed something to work with, i removed both from css

cleanInitialState();

function updateCountDown() {
remainingSeconds = totalSeconds;
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.

You have already assigned totalSeconds to remainingSeconds on line 16, why not just use only remainingSeconds in the remaining part of the function?

Comment on lines +30 to +35
let seconds = totalSeconds % 60;
let minutes = (totalSeconds - seconds) / 60;

let paddedSeconds = seconds.toString().padStart(2, "0");
let paddedMinutes = minutes.toString().padStart(2, "0");
timeRemainingEl.innerHTML = `Time Remaining: ${paddedMinutes}:${paddedSeconds}`;
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.

Better to implement the logic to "update the displayed time" in a function, and then use a function call to replace the code on lines 30-35, 66-71, 85.

Pros:

  • Centralised logic (improved maintainability)
  • Less code

Comment on lines +60 to +78
intervalId = setInterval(() => {
if (remainingSeconds <= 0) {
clearInterval(intervalId);
return;
}
remainingSeconds -= 1;
const seconds = remainingSeconds % 60;
const minutes = (remainingSeconds - seconds) / 60;
const paddedSeconds = seconds.toString().padStart(2, "0");
const paddedMinutes = minutes.toString().padStart(2, "0");
document.getElementById("timeRemaining").innerHTML =
`Time Remaining: ${paddedMinutes}:${paddedSeconds}`;

if (remainingSeconds <= 0) {
document.body.classList.add("finish-countdown");
playAlarm();
clearInterval(intervalId);
}
}, 1000);
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.

It seems the code here is very similar to those perform in setAlarm(). Can you try reusing the code you have in setAlarm()?

@alexandru-pocovnicu alexandru-pocovnicu 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 Apr 6, 2026
function cleanInitialState() {
clearInterval(intervalId);
document.body.classList.remove("finish-countdown");
document.getElementById("timeRemaining").innerHTML = "Time Remaining: 00:00";
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.

Could also call updateDiplayedTime(0) to keep the logic of displaying time in one place.

Comment on lines +6 to +8
const pauseButton = document.getElementById("pause-button");
pauseButton.textContent = "Pause";
pauseButton.addEventListener("click", pauseCountDown);
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.

You can reset the isPaused flag and the "Pause" button state in cleanInitialState(), and add event listener only once on page load.

Currently, the same event listener will be added to the button multiple times (once per function call).

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.

but if i move the listener inside cleanInitialState(), which is called everytime setAlarm() is called, isn't that the same thing, how about instead, i remove the listener inside setAlarm just before adding it?
thank you

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.

I mean, perform this in cleanInitialState()

    const pauseButton = document.getElementById("pause-button");
    pauseButton.textContent = "Pause";

and perform this on page load

window.addEventListener("load", function() {
    const pauseButton = document.getElementById("pause-button");
    pauseButton.addEventListener("click", pauseCountDown);
});

@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 6, 2026
@alexandru-pocovnicu alexandru-pocovnicu 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 Apr 9, 2026
clearInterval(intervalId);
document.body.classList.remove("finish-countdown");
updateDisplayedTime(0)
document.getElementById("alarmSet").value = null;
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.

.value is a string, so better to write document.getElementById("alarmSet").value = "";.

Comment on lines +6 to +8
const pauseButton = document.getElementById("pause-button");
pauseButton.textContent = "Pause";
pauseButton.addEventListener("click", pauseCountDown);
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.

I mean, perform this in cleanInitialState()

    const pauseButton = document.getElementById("pause-button");
    pauseButton.textContent = "Pause";

and perform this on page load

window.addEventListener("load", function() {
    const pauseButton = document.getElementById("pause-button");
    pauseButton.addEventListener("click", pauseCountDown);
});

@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 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants