-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Open
bytesandroses
wants to merge
15
commits into
CodeYourFuture:main
Choose a base branch
from
bytesandroses:coursework/Sprint-3/alarm-clock
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
104bc75
Rename app title
bytesandroses bc9db0d
Implement set Alarm
bytesandroses 2e9abac
Refactor: remove duplicate setAlarm button event listener
bytesandroses 15cd7d0
Refactor: remove duplicate stopAlarm button event listener
bytesandroses 01299b1
Refactor: separate time display into a function
bytesandroses 13a05e6
Refactor: improve readability
bytesandroses 7a55810
Feat: allow alarm to countdown
bytesandroses d0daf34
Refactor: move timer countdown into separate function
bytesandroses 47e2f22
Refactor alarm countdown
bytesandroses 5fcb0b1
Fix: add 0 in front of minutes when single digit
bytesandroses 98a0a64
Fix: prevent multiple setInterval timers running at the same time
bytesandroses dfa1f57
Fix: update timer value immediately after button is clicked
bytesandroses cb65771
Fix: ensure timer stops at 00:00 and doesn't go below
bytesandroses eeb1c24
Refactor: improve readability of formatTime() function
bytesandroses f165cf5
Validate and sanitize user's time input
bytesandroses File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,54 @@ | ||
| 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; | ||
|
|
||
| const numericTime = parseInt(setTime, 10); | ||
| if (isNaN(numericTime)) { | ||
| alert( | ||
| "Please enter your desired time in numbers, e.g., 120 for 2 minutes." | ||
| ); | ||
| return; | ||
| } | ||
| if (numericTime < 0) { | ||
| alert("Please enter a non-negative number."); | ||
| return; | ||
| } | ||
|
|
||
| timeRemaining = numericTime; | ||
|
|
||
| if (timerInterval) { | ||
| clearInterval(timerInterval); | ||
| } | ||
|
Comment on lines
+46
to
+48
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"); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.