-
-
Notifications
You must be signed in to change notification settings - Fork 283
London |ITP- Jan-2026| Ping Wang|Sprint 3 |Alarm clock #1024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,44 @@ | ||
| function setAlarm() {} | ||
| let countdownInterval = null; | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| let totalSeconds = parseInt(input.value); | ||
|
|
||
| if (isNaN(totalSeconds) || totalSeconds <= 0) { | ||
| alert("Please enter a valid positive number."); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| if (countdownInterval) clearInterval(countdownInterval); | ||
|
|
||
| function updateHeading() { | ||
| const minutes = Math.floor(totalSeconds / 60); | ||
| const seconds = totalSeconds % 60; | ||
| heading.textContent = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| updateHeading(); | ||
|
|
||
| countdownInterval = setInterval(() => { | ||
| totalSeconds--; | ||
|
|
||
| if (totalSeconds <= 0) { | ||
| totalSeconds = 0; | ||
|
|
||
| updateHeading(); | ||
|
|
||
| clearInterval(countdownInterval); | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
|
|
||
| updateHeading(); | ||
| }, 1000); | ||
| } | ||
|
Comment on lines
+25
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The alarm will play before the seconds remaining are set to exactly 0, how can we improve that?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the alarm is triggered before the UI clearly shows 00:00, so it feels early. I amend my code in order to update the UI before triggering the final action |
||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if we add -5 or not add anything to the timer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a negative value will trigger the alarm right away (or nearly immediately) and empty input breaks the timer unless handled. so i correct my code if (isNaN(totalSeconds) || totalSeconds <= 0) {
alert("Please enter a valid positive number.");
return;
} to make sure the code is running smoothly