generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 222
Sheffield | 25-ITP-SEP | Declan Williams | Sprint 3 | Alarm clock #846
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
Closed
CatchingKiyoko
wants to merge
22
commits into
CodeYourFuture:main
from
CatchingKiyoko:alarm-clock-sprint-3
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3a34f9f
updated title name placeholder to Alarm clock app
CatchingKiyoko 0289a03
implemented: selects the users input field from the DOM to retrieve s…
CatchingKiyoko b3fb326
implemented: Select DOM element that displays the remaining time for …
CatchingKiyoko 192ccee
implemented: convert user input into a number
CatchingKiyoko 273cafc
fix: correct typo in number conversion for user input
CatchingKiyoko 5fe19ee
implemented: add function to format and update time display in setAlarm
CatchingKiyoko 3c31af3
added: Ensure countdown timer displays two-digit minutes and seconds …
CatchingKiyoko 21f33e2
implemented: call updatedTime function to display initial countdown time
CatchingKiyoko b0c3c0c
fix: validate user input for positive number in setAlarm function
CatchingKiyoko f3f61ed
fixed typo error with isNaN
CatchingKiyoko 7b868a2
corrected typo for textContext to textContent
CatchingKiyoko a8fb6fb
fix: clear existing interval before starting a new countdown timer an…
CatchingKiyoko 28b9e82
fix: clear existing interval before starting a new countdown timer an…
CatchingKiyoko f958c48
fix: ensure countdown timer clears interval and displays "times up!" …
CatchingKiyoko e07ee1c
fix: clarify return statement for "times up!" message in countdown timer
CatchingKiyoko 92bbd26
fix: correct interval closure in setAlarm function to correctly run f…
CatchingKiyoko 3c99f1c
fix: ensure alarm plays when countdown reaches zero
CatchingKiyoko 78e82d8
fix: add comment to clarify interval update frequency in setAlarm fun…
CatchingKiyoko f617770
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko 587b3f1
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko 79db61d
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko 2e30b5d
Merge branch 'CodeYourFuture:main' into alarm-clock-sprint-3
CatchingKiyoko 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,4 +1,50 @@ | ||
| function setAlarm() {} | ||
| function setAlarm() { | ||
| // get the users input in seconds from the input element | ||
| const inputField = document.getElementById("alarmSet"); | ||
|
|
||
| // get the "timeRemaining" element where we show the time | ||
| const timeDisplay = document.getElementById("timeRemaining"); | ||
|
|
||
| // convert the users input to a number | ||
| let secondsRemaining = Number(inputField.value); | ||
|
|
||
| // check if input is not a number or less than or equal to zero and informs the user to enter a positive number | ||
| if (isNaN(secondsRemaining) || secondsRemaining <= 0){ | ||
| timeDisplay.textContent = "Enter a positive number."; | ||
| return; | ||
| } | ||
|
|
||
| // format and update the time display with a function | ||
| function updatedTime(){ | ||
| // calculate the number into minutes and seconds | ||
| const minutes = Math.floor(secondsRemaining / 60); | ||
| const seconds = secondsRemaining % 60; | ||
|
|
||
| // pad the numbers to ensure double digits so it looks right and is easily readable | ||
| const formattedTime = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; | ||
| timeDisplay.textContent = `Time Remaining: ${formattedTime}`; | ||
|
|
||
| } | ||
| updatedTime() // shows the starting time | ||
|
|
||
| let intervalId; // store a global variable to the interval so we can clear it later | ||
|
|
||
| // Start the countdown interval | ||
| intervalId = setInterval(() => { | ||
|
|
||
| // decrement the number to reduce the countdown | ||
| secondsRemaining--; | ||
|
|
||
| // check if the timer has reached 0 | ||
| if (secondsRemaining < 0){ | ||
| clearInterval(intervalId); // clear the interval when timer reaches 0 | ||
| timeDisplay.textContent = "times up!" // returns times up when timer reaches 0 | ||
| return playAlarm(); | ||
| } else { | ||
| updatedTime(); | ||
| } | ||
| }, 1000); // updates the function by running it every 1000ms | ||
|
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. Here, |
||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
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.
There is a bug in your program, suppose the user clicks on the
Set Alarmbutton while the previous alarm is running.