Skip to content

Cape Town| 26-ITP-May | Liyema Mfengwana| Sprint 3 | Alarm clock app - #1417

Open
LiyemaMfengwana wants to merge 14 commits into
CodeYourFuture:mainfrom
LiyemaMfengwana:alarm-clock
Open

Cape Town| 26-ITP-May | Liyema Mfengwana| Sprint 3 | Alarm clock app#1417
LiyemaMfengwana wants to merge 14 commits into
CodeYourFuture:mainfrom
LiyemaMfengwana:alarm-clock

Conversation

@LiyemaMfengwana

Copy link
Copy Markdown

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

Clock alarm app complete

@LiyemaMfengwana LiyemaMfengwana added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Aug 10, 2026
setTimeout(countdown, 1000);
}

countdown();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try in the browser: set the alarm to 30, then straight away change the input to 10 and click Set Alarm again.

What do you expect to happen? What actually happens?

Think about how many countdowns are running at that point, and what each one is doing to the heading. setTimeout returns something when you call it and that might be useful.

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! I've made the requested changes:

Added validation for empty and non-positive input.
Added min="1" to prevent negative values through the number input.
Changed variables to const where they aren't reassigned.
Stored the setTimeout ID.
Prevented users from setting a new alarm while a countdown is already running by disabling the Set Alarm button.
Re-enabled the button once the countdown finishes.

document.getElementById("timeRemaining").textContent =
`Time Remaining: ${formattedMinutes}:${formattedSeconds}`;

if (seconds === 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 cases to check

  1. Click Set Alarm with the input left empty. What does Number("") give you?
  2. The input is type="number", so a user can type -5. Try it pls.

Comment thread Sprint-3/alarmclock/alarmclock.js Outdated
let remainingSeconds = seconds % 60;

let formattedMinutes = String(minutes).padStart(2, "0");
let formattedSeconds = String(remainingSeconds).padStart(2, "0");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use const instead of let. let only for something that changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants