-
-
Notifications
You must be signed in to change notification settings - Fork 326
Birmingham | 26-ITP-May | Tobias Amaechina | Sprint 3 | Sprint/alarm-clock #1332
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
Tobias-Amaechina
wants to merge
28
commits into
CodeYourFuture:main
Choose a base branch
from
Tobias-Amaechina:group-data-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
28 commits
Select commit
Hold shift + click to select a range
eb0ec17
updated the Title of alarm clock template file
Tobias-Amaechina b45f3d2
Created a global varible to hold remaining time and the interval id
Tobias-Amaechina 4e3b1d2
implement a function that set the alarm
Tobias-Amaechina 51dfb2e
Implements function to display updates on the page
Tobias-Amaechina 55ab312
Implement a function that stops the alarm
Tobias-Amaechina e418ebc
set alarm button and add event listener
Tobias-Amaechina 6a0c87e
add stop alarm button and add event listener
Tobias-Amaechina 7b7a44a
updated the wrong name variable in the input variable and Title vari…
Tobias-Amaechina 84985a9
removed the broken event listeners
Tobias-Amaechina dfa54e5
Add Node to interact with the styling document
Tobias-Amaechina 6208876
declate a booleen varaible an set to false
Tobias-Amaechina 7e08577
add a pause button element in the template
Tobias-Amaechina d4458e2
deleted broken functions and updated Id pause name
Tobias-Amaechina 4c8eeb9
added into the set alarm function A note for flashing
Tobias-Amaechina 67ca5df
Add event listener to stop the flash
Tobias-Amaechina 0496416
created a global variable to toggle pause an set it to false
Tobias-Amaechina b2b7638
created a function to toggle and pause
Tobias-Amaechina df1b2f4
wire the pause button to togglepause
Tobias-Amaechina 5896a93
updated the style sheet to have the animation
Tobias-Amaechina a940501
changed the Title in the template as Alarm clock app
Tobias-Amaechina 3a4bb35
Create a newfunction startCountdown and remove the duplicated code
Tobias-Amaechina 6a5d331
clears time with intervalId to null
Tobias-Amaechina f9ad3be
created a check to check if intervalId is null
Tobias-Amaechina f057c76
Created logical AND to check for finshsed timer
Tobias-Amaechina 80d4b45
Trimm empty spaces
Tobias-Amaechina c283013
wrote a statement to check for empty input
Tobias-Amaechina cad0b79
wrote a tatement to validate that the input is a positive number and…
Tobias-Amaechina 7740b88
Wrote a statement for stronger validation . added a reset function …
Tobias-Amaechina 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,98 @@ | ||
| function setAlarm() {} | ||
| let timeRemaining = 0; | ||
| let intervalId = null; | ||
| let isPaused = false; | ||
|
|
||
| function reset() { | ||
| // 1. Stop any active interval timer and clear the ID | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
|
|
||
| // 2. Reset the state variables back to default | ||
| timeRemaining = 0; | ||
| isPaused = false; | ||
|
|
||
| // 3. Stop visual and audio effects | ||
| document.body.classList.remove("flash"); | ||
| pauseAlarm(); | ||
|
|
||
| // 4. Update the screen display back to 00:00 | ||
| updateDisplay(0); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const value = input.value.trim();//trim empty string | ||
| //Check if the input is empty | ||
| if (value === "") { | ||
| alert("Please enter a number of seconds."); | ||
| return; | ||
| } | ||
|
|
||
| const seconds = Number(value); | ||
| //validate that input is a positive integer and doestn't exceed 1 hour | ||
| if ( | ||
| isNaN(seconds) || | ||
| !Number.isInteger(seconds) || | ||
|
Comment on lines
+34
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. One of these checks is redundant. |
||
| seconds <= 0 || | ||
| seconds > 3600 | ||
| ) { | ||
| alert("Please enter a valid whole number between 1 and 3600."); | ||
| return; | ||
| } | ||
| reset(); | ||
|
|
||
| timeRemaining = seconds; | ||
| isPaused = false; | ||
| updateDisplay(timeRemaining); | ||
| // Start a new countdown | ||
| startCountdown(); | ||
|
Comment on lines
+47
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. This comment is probably not needed. |
||
| } | ||
|
|
||
| function startCountdown() { | ||
| if (intervalId !== null) { | ||
| return; | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
|
|
||
| intervalId = setInterval(() => { | ||
| timeRemaining--; | ||
| updateDisplay(timeRemaining); | ||
|
|
||
| if (timeRemaining <= 0) { | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
| playAlarm(); | ||
| document.body.classList.add("flash"); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| function updateDisplay(seconds) { | ||
| const title = document.getElementById("timeRemaining"); | ||
|
|
||
|
|
||
| const mins = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
| const secs = String(seconds % 60).padStart(2, "0"); | ||
|
|
||
| title.textContent = `Time Remaining: ${mins}:${secs}`; | ||
| } | ||
| function togglePause() { | ||
| if (intervalId === null && !isPaused) { | ||
| return; | ||
| } | ||
|
|
||
| if (!isPaused) { | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
| isPaused = true; | ||
| } else { | ||
| isPaused = false; | ||
| startCountdown(); | ||
| } | ||
| } | ||
| document.getElementById("pause").addEventListener("click", togglePause); | ||
| document.getElementById("stop").addEventListener("click", reset); | ||
|
|
||
|
|
||
|
|
||
| // 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
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
Oops, something went wrong.
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.
The code is clear and readable enough. I don't think these comments could make the code any clearer.