London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 3 | coursework/AlarmClock#1084
London | ITP-JAN-2026 | Said Fayaz Sadat | Sprint 3 | coursework/AlarmClock#1084fayaz551 wants to merge 5 commits intoCodeYourFuture:mainfrom
Conversation
There was a problem hiding this comment.
The html title should be "Alarm clock app"
| @@ -1,4 +1,31 @@ | |||
| function setAlarm() {} | |||
| function setAlarm() { | |||
There was a problem hiding this comment.
What happens when the user sets an alarm when the countdown is already running?
There was a problem hiding this comment.
If a user sets a new alarm while one is already running, the original code would create multiple overlapping timers.
I moved the timerInterval variable to a global scope and added clearInterval(timerInterval) at the start of the setAlarm function to fix it.
| const minutes = Math.floor(remainingTime / 60); | ||
| const seconds = remainingTime % 60; | ||
|
|
||
| heading.textContent = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; |
There was a problem hiding this comment.
This 3 lines of code are also repeated in line 24. How could you make the code reusable?
There was a problem hiding this comment.
To make the code reusable, I extracted the time formatting and DOM update logic into a separate helper function called updateDisplay(time).
| const time = document.getElementById("alarmSet").value; | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| let remainingTime = Number(time); |
There was a problem hiding this comment.
What happens when the user enters a negative number or a string value?
There was a problem hiding this comment.
If a user enters a string, Number(time) results in NaN, causing the display to show 'NaN:NaN'. If they enter a negative number, the remainingTime <= 0 check passes immediately, triggering the alarm instantly without a countdown.
To prevent this, I added a validation check at the beginning of the function to ensure the input is a positive number before starting the interval.
There was a problem hiding this comment.
Well done. It's important to validate user input. How could you inform the user about the incorrect data?
|
Closing PR because the January ITP run has finished. Feel free to re-open if you're still working on it. |
Learners, PR Template
Self checklist
Changelist
implemented the AlarmClock function to work properly with jest test cases.
Questions
n/a