Glasgow | 26-ITP-May | Sandani Kannangara | Sprint 3 | Alarm Clock - #1276
Glasgow | 26-ITP-May | Sandani Kannangara | Sprint 3 | Alarm Clock#1276SandzSoft wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
72ce6e9 to
be8fbab
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
LonMcGregor
left a comment
There was a problem hiding this comment.
Good start on this task, there are a few things to fix
| let timer = setInterval(() => { | ||
| remainingSeconds--; | ||
| displayTimeRemaining(); | ||
| if (remainingSeconds === 0) { |
There was a problem hiding this comment.
Does the alarm clock stop correctly after it reaches zero?
| remainingSeconds = Number(alarmTime.value); | ||
| displayTimeRemaining(); | ||
|
|
||
| let timer = setInterval(() => { |
There was a problem hiding this comment.
What happens if you start a timer when one is already running?
There was a problem hiding this comment.
Thanks for the review Leon! Your comments helped me realize that my mental model of setInterval was wrong.
I originally thought setInterval was just another JavaScript function like map() or filter(). While fixing the review comments, I learned that setInterval() actually asks the browser to create and manage an interval timer, and the variable only stores the timer ID/reference returned by the browser. That understanding also helped me see why clearInterval(timer) works.
I also updated the code to prevent multiple timers from running at the same time and added input validation. Thanks again for the helpful feedback!
| let remainingSeconds; | ||
|
|
||
| function setAlarm() { | ||
| remainingSeconds = Number(alarmTime.value); |
There was a problem hiding this comment.
Have you properly handled your input validation?
| @@ -1,4 +1,31 @@ | |||
| function setAlarm() {} | |||
| const alarmTime = document.querySelector("#alarmSet"); | |||
There was a problem hiding this comment.
If you know the id you are using, there is a better method to use than querySelector, do you know which?
LonMcGregor
left a comment
There was a problem hiding this comment.
Good work, this looks better. Task complete. Good explanation about how timers and intervals work in js.
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
Implemented alarm clock features.