Repository navigation
Conversation
|
|
||
| function setAlarm() { | ||
| clearInterval(timer); // stop any old countdown | ||
| timeLeft = Number(document.getElementById("alarmSet").value); |
There was a problem hiding this comment.
What happens when Set Alarm is clicked with the number field left empty?
To "like" or "dislike" this comment, please follow this link
|
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. |
eliza-an
left a comment
There was a problem hiding this comment.
Really great job here! some little bits and pieces for you, nothing crucial. You dont have to make changes but i just left some comments for your future learning ! well done
| const minutes = Math.floor(timeLeft / 60); | ||
| const seconds = timeLeft % 60; | ||
| const text = | ||
| String(minutes).padStart(2, "0") + ":" + String(seconds).padStart(2, "0"); |
There was a problem hiding this comment.
This is a really good little piece of code, but as a developer, your main job is to ensure your code is clear and readable. I love that you named your variables "minutes" and "seconds" as it makes it easy to review, but could you maybe write this next bit clearer? Could we use variables and string concatination to do this? Have a look :)
There was a problem hiding this comment.
Thanks for the feedback! I've separated the formatting into variables to make the code clearer and easier to read.
| clearInterval(timer); | ||
|
|
||
| const input = document.getElementById("alarmSet").value; | ||
| if (input.trim() === "") { |
There was a problem hiding this comment.
very interesting way of checking this!! Unusual but not bad!
| } | ||
| timeLeft = Number(input); | ||
|
|
||
| if (timeLeft <= 0 || !Number.isFinite(timeLeft)) { |
There was a problem hiding this comment.
Good point, I hadn't considered decimal inputs. I'll add Number.isInteger() to make sure only whole numbers are accepted.
| clearInterval(timer); | ||
|
|
||
| const input = document.getElementById("alarmSet").value; | ||
| if (input.trim() === "") { |
There was a problem hiding this comment.
very interesting way of checking this!! Unusual but not bad!
| const text = | ||
| String(minutes).padStart(2, "0") + ":" + String(seconds).padStart(2, "0"); | ||
|
|
||
| const formattedMinutes = String(minutes).padStart(2, "0"); |


Self checklist
Task code
CYF-1098
Changelist
Fixed alarm clock code