-
-
Notifications
You must be signed in to change notification settings - Fork 278
Cape Town | 2026-ITP-Jan | Isaac Abodunrin | Sprint 3 | Grouping data: Alarm Clock #1182
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
base: main
Are you sure you want to change the base?
Changes from all commits
104bc75
bc9db0d
2e9abac
15cd7d0
01299b1
13a05e6
7a55810
d0daf34
47e2f22
5fcb0b1
98a0a64
dfa1f57
cb65771
eeb1c24
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,6 +1,42 @@ | ||
| function setAlarm() {} | ||
| let timeRemaining; | ||
| let timerInterval; | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| function formatTime(time) { | ||
| const minutes = String(Math.floor(time / 60)).padStart(2, "0"); | ||
| const seconds = String(time % 60).padStart(2, "0"); | ||
|
|
||
| return `${minutes}:${seconds}`; | ||
| } | ||
|
|
||
| function displayAlarm(time) { | ||
| const alarmBox = document.getElementById("timeRemaining"); | ||
| alarmBox.textContent = `Time Remaining: ${formatTime(time)}`; | ||
| } | ||
|
|
||
| function decreaseAlarmTime() { | ||
| if (timeRemaining <= 0) { | ||
| clearInterval(timerInterval); | ||
| timerInterval = null; | ||
| timeRemaining = 0; | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
| timeRemaining--; | ||
| displayAlarm(timeRemaining); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const setTime = document.getElementById("alarmSet").value; | ||
| timeRemaining = parseInt(setTime, 10); | ||
|
Contributor
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. Using user input without proper validation and sanitisation can be dangeours. Currently, some unusual input values can make your app behave abnormally. Can you add code to sanitise them? |
||
|
|
||
| if (timerInterval) { | ||
| clearInterval(timerInterval); | ||
| } | ||
|
Comment on lines
+33
to
+35
Contributor
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 countdown interval is not the only state to be reset. Hint: a user may not click the "Stop" button first before starting a new count down. You can also consider introducing a dedicated reset function to return the app to a clean initial state to help ensure consistency. |
||
|
|
||
| displayAlarm(timeRemaining); | ||
| timerInterval = setInterval(decreaseAlarmTime, 1000); | ||
| } | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
|
|
||
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.
When the countdown reaches 00:00, there is a one second delay before the alarm sound is played. Is this by design?
At line 25, when
timeRemainingchanges from 1 to 0, the app only changes the display to 00:00. It's only in the next interval, the code on lines 17-22 is executed.