Skip to content

London | 26-ITP-Sept | Hugh Mills | Sprint 3 | Alarmclock - #1588

Open
HM-127BTY wants to merge 9 commits into
CodeYourFuture:mainfrom
HM-127BTY:Alarmclock
Open

HM-127BTY wants to merge 9 commits into
CodeYourFuture:mainfrom
HM-127BTY:Alarmclock

Conversation

@HM-127BTY

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • [x ] 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

Task code

CYF-1098

Changelist

Worked on code to make sure an Alarm clock works while displaying current time left before playing an audio file.

@HM-127BTY HM-127BTY 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. labels Nov 30, 2026

const timer = setInterval(() => {
alarmTimeRemaining = alarmTimeRemaining - 1;
if (alarmTimeRemaining === 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.

What happens when the input is left blank or set to 0? After the first tick, can alarmTimeRemaining === 0 still become true?

To "like" or "dislike" this comment, please follow this link

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.

Yes it does as Number() takes a black input and makes it into 0, so it will become true.

@cyf-ai-code-reviewer cyf-ai-code-reviewer Bot 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 Nov 30, 2026
@cyf-ai-code-reviewer

Copy link
Copy Markdown

The CYF AI review has left comments. It will only review a PR one time. When you have addressed these comments, please request review again and a volunteer will take a look.

@HM-127BTY HM-127BTY added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 30, 2026

@eliza-an eliza-an 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.

Have a look at my comment. Thsi code is great! But i just want to make sure you are understanding everything that you are writing and why.

const sec = alarmTimeRemaining % 60;

document.getElementById("timeRemaining").textContent =
`Time Remaining: ${String(min).padStart(2, "0")}:${String(sec).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.

This is a really complex piece of code for your level. Well done for using it! Can you explain what each section does?
Why do we need the $?
Why are you using ` instead of "?
What does padStart do and why is the input 2 and "0"?
The code is good, but your understnading is so much more important. Can you come back with a detailed explanation of this for me?

@HM-127BTY HM-127BTY Dec 2, 2026 •

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.

Sure, ill try my best.

  1. The $ is used with {} to insert a variable into a string such as Hi I am ${name}. I cant remember exactly what its called right now.

  2. The ` is a template that lets me use the ${} and variables for s string, it also lets me use " or ' inside it.

  3. padStart makes sure that it fills in from left to right for the string, so there are always going to be the amount I set, which is (2) in this case and will fill empty areas with the (0) I selected. So when I is empty it will show "00" and if its 1 it will show (01)

@HM-127BTY HM-127BTY Dec 2, 2026 •

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.

Oh sorry missed the each section bit:
document.getElementById("timeRemaining")
This lets me link the HTML with the code, looking for the id of
timeRemaining from teh index.html, line 11: <h1 id="timeRemaining">Time Remaining: 00:00</h1>

.textContent
is an HTMLScriptElement that lets me change the text to be what I set it to be for the id I have selected, in this case teh timeRemaining.

``Time Remaining: ${String(min).padStart(2, "0")}:${String(sec).padStart(2, "0")};
This is the test string I have between the `, then the ${} contains the variable to put in, for the first one its String(min). This changes the numbers to a string so I can then use padStart to make sure it is always showing numbers at least 00. It does this aswell for the sec.

This lets me show on the HTML "Time Remaining 00:00" for the h1 area for timeRemaining.

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 tried to use the ` in there to show code blocks in my reply and i see it messed up a bit ^_^

@eliza-an eliza-an removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 2, 2026
}
const min = Math.floor(alarmTimeRemaining / 60);
const sec = alarmTimeRemaining % 60;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just another note, what happens if a negative number gets entered into the field? perhaps you could think of some ways to ensure this doesnt happen?

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 didnt think of that... could have it throw an error just just become 0 instantly... ill sort that out

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 used Math.max(0, timeRemainig) to do that, this ensures that it cant be bellow 0 and putting in a negative number will trigger the alarm as though a 0 input was given.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Interesting choice! I wouldnt have thought of that!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unfortunately it doesnt work ! Have you tested it on your machine?

image

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 see what I did... I didnt test the app on the site, I used the "npm test --...." I got it sorted out now.

Think I'm racing and stressing myself out trying to play catch-up at the moment, need to chill a lille more and focus with a clear head ^_^

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.

Interesting choice! I wouldnt have thought of that!

I thought about it, if you have a clock jsut showing a screen and somehow put in a negative.. the simple way for a user is to trigger the alarm rather an displaying an error code.

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 discovered another bug, more inputs before the timer goes off makes it having multiple countdowns in the same number area making it very wierd graphic glitch as the numbers override each other. Also when it hits the first alarm it can skip and start a negitive countdown.

So added in clearInterval at the start of the function so every input clears the last. also having "let timer" outside the function so there is just 1 "timer" to run and not one for each time the function starts.... well I think thats how it works ^_^

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It does sound lik eyou need a bit of a break. Take a beat and come back to this, thats how the best solutions happen
Unfortunately now if i enter a negative numevr the alarm jsut stats going off right away.
Take a minute, you're doing really well and come back tomorrow. I will be here to review it for you!

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.

That is what I was planning to do with it. Having it set off the alarm if its at 0 or bellow as you cant ccount down negatives. Should it rather show an error instead or do nothing if giving a negative, or force positive?

yeah Having a break from teh coding for a lille, unwind and tackle some more later tonight ^_^

@HM-127BTY HM-127BTY added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 2, 2026
@eliza-an eliza-an removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 3, 2026
… of function to check for negatives, will also trigger for "0" and empty inputs.
@HM-127BTY HM-127BTY added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 3, 2026
added "let timer;" outside function to aid in double input then at start of function had "clearInterval(timer)" so every input will clear the last one.
@eliza-an eliza-an removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 3, 2026
@HM-127BTY HM-127BTY added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 4, 2026
clearInterval(timer);
}
const alarmTime = Number(document.getElementById("alarmSet").value);
let alarmTimeRemaining = Math.max(0, alarmTime);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

okay , this is the last bit you need to fix. Try entering a negative number in the input. What happens?
The alarm starts ringing immediately. Can you tell me why based on this line?

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.

Sure, when a negative number in put in the Math.max makes it 0 as I have 0 as the max that the number can be so anything under 0, in this case a negative, becomes 0. As I have no "return" or anything stopping the code there it goes to the next step which is the "setInterval".

This sees the value of 0 so it triggers the alarm, in the same was if you typed in 0.

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.

If I need to do something different for this please let me know as I can't seam to spot anything to change.

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 alarm starts ringing immediately when you put in a negative number. Thats not the intended functionality and so is a bug. You don't want the user to be able to put in a negative number at all, and you definitely don't want the alarm to start ringing immediately:) does that clear it up?

@eliza-an eliza-an removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 4, 2026
@HM-127BTY HM-127BTY added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Dec 4, 2026
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. 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