Glasgow| 2026-ITP-Jan | Tuan Nguyen| Sprint 3 | Alarm clock#1209
Glasgow| 2026-ITP-Jan | Tuan Nguyen| Sprint 3 | Alarm clock#1209Jacknguyen4438 wants to merge 7 commits intoCodeYourFuture:mainfrom
Conversation
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| let time = Number(input.value); |
There was a problem hiding this comment.
What type and range of number should time be? Invalid user input could cause the app to behave abnormally.
There was a problem hiding this comment.
Thank you for the feed back I have add validation cod to help with this here is my validation code below:
if (isNaN(time) || time < 0) {
updateHeading(0);
return;
}
There was a problem hiding this comment.
What do you expect the app to behave when the user enters 3.14 as input?
There was a problem hiding this comment.
Thank you for the feed back here is my explain when decimal is pass down:
If the user enters 3.14, Number() converts it to a floating‑point number.
The countdown will decrease by 1 each second (3.14 → 2.14 → 1.14 → 0.14 → alarm), but the display will show whole seconds because of the formatting.
const minutes = Math.floor(time / 60);
const seconds = time % 60;
This behaviour is technically valid but not intuitive for users, since countdown timers usually expect whole seconds.
A more predictable behaviour would be to either:
reject decimal input as invalid, or
convert it to an integer using Math.floor() or Math.round().
This would make the app’s behaviour clearer and more consistent.
Thank you for the reading and I will some change base on this explanation to make sure the function work properly.
There was a problem hiding this comment.
In general if you're just ignoring user input (as you do if someone puts in a float), it's good to show an error message telling them what's wrong, rather than just ignore it.
Also, if you already had an alarm counting down, then submitted 1.2, it will set to 00:00 but then shortly after start counting down again.
Can you fix up both of these things?
There was a problem hiding this comment.
Hello @illicitonion thank you for your feed back I have understand what your like to ask me to do so here is my validation code that will show on the HTML page:
if (isNaN(time) || time < 0 || !Number.isInteger(time)) {
showError("Please enter a whole number of seconds.");
return;
}
|
Hello @cjyuan, thank you for your review my code is ready to be review again if you need me to max more change please let know. |
|
Hello @cjyuan and thank you for the feed back I make small change so that the function can correctly handle float number. Also I have answer some of the question you would like me to answer. I hope to hear from you soon thank you |
|
@illicitonion Hello and thank you for your time review my PR, I have make change to fit with you feed back if I need make change for the error message please let me know |
|
Changes look good. |
| const heading = document.getElementById("timeRemaining"); | ||
| heading.innerText = message; |
There was a problem hiding this comment.
Would be better to introducing a separate element to showing message.
There was a problem hiding this comment.
@cjyuan thank you for you reply I have making change that now will display the error without interfering with the heading element in HTML page. Here is my solution:
function showError(message) {
const heading = document.getElementById("errorMessage");
heading.innerText = message;
}
function setAlarm() {
const input = document.getElementById("alarmSet");
let time = Number(input.value);
resetAlarm();
if (isNaN(time) || time < 0 || !Number.isInteger(time)) {
showError("Please enter a whole number of seconds.");
return;
}
document.getElementById("errorMessage").innerText = "";
for better checking I have make an commit with full code so you can check for better view of the whole code. Thank you.
Learners, PR Template
Self checklist
Changelist
Hello I have the function alarm clock and is working correctly. If additional change need to be done I will fix it right away.
Questions
If this PR have been done mark as completed, can I come back and do the additional task later?