-
-
Notifications
You must be signed in to change notification settings - Fork 283
London|26-ITP-January|Alexandru Pocovnicu|Sprint 3| alarm clock #1057
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
alexandru-pocovnicu
wants to merge
32
commits into
CodeYourFuture:main
Choose a base branch
from
alexandru-pocovnicu: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 13 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
47f91e5
Fix: update document title to 'Alarm clock app'
alexandru-pocovnicu 41537a4
Fix: implement setAlarm function to display time remaining
alexandru-pocovnicu 3ab9799
extract the seconds and minutes
alexandru-pocovnicu 8a4ba11
Refactor: enhance setAlarm function to improve countdown display and …
alexandru-pocovnicu ca62e47
change background to blue when stop alarm is selected
alexandru-pocovnicu 08fbcbd
alternate background color
alexandru-pocovnicu aa8df3b
deleted code for remove class
alexandru-pocovnicu 950cd4a
added return when the input is 0, so timer doesn't start
alexandru-pocovnicu 4aafd50
added function to clean the initial state
alexandru-pocovnicu dc665e5
add checks for valid input
alexandru-pocovnicu b81719d
create pause button,
alexandru-pocovnicu 8354926
refactor CSS for consistency and clarity
alexandru-pocovnicu 063a0fa
addresse reviewer's changes
alexandru-pocovnicu 5d64c66
delete redundant code
alexandru-pocovnicu c84e2a9
created function to update display
alexandru-pocovnicu 894313e
move countdown logic to finishCountDown()
alexandru-pocovnicu 3b6db49
remove unused pause button styles and empty unpause-alarm class
alexandru-pocovnicu 11d7474
capitalize unpause button text in pauseCountDown function
alexandru-pocovnicu 5209ca9
remove class
alexandru-pocovnicu 4251c18
remove id attribute from pause button in setAlarm function
alexandru-pocovnicu a65ca54
set pause button text and ensure event listener is added in setAlarm …
alexandru-pocovnicu 6d09014
use display time logic instead of hard coding it
alexandru-pocovnicu 6799a86
refactor cleanInitialState to use updateDisplayedTime for resetting d…
alexandru-pocovnicu fbb165f
initialize isPaused in cleanInitialState function
alexandru-pocovnicu 74c4c23
remove event listener for pause button before adding a new one in set…
alexandru-pocovnicu 35c4a7c
remove redundant assignment of remainingSeconds in setAlarm function
alexandru-pocovnicu 5e723c2
move pause button listener to window load
alexandru-pocovnicu 4de7371
set alarm input value to an empty string in cleanInitialState function
alexandru-pocovnicu 9ebd673
remove commented-out code for pause button in setAlarm function
alexandru-pocovnicu 8c26043
remove unused variable declaration for timeRemaining element in setAl…
alexandru-pocovnicu 3c1df8c
refactor updateCountDown function to use shared remainingSeconds logi…
alexandru-pocovnicu 4685a7a
add stop button functionality to reset countdown and clean state
alexandru-pocovnicu 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,91 @@ | ||
| function setAlarm() {} | ||
| let intervalId; | ||
| let isPaused; | ||
| let remainingSeconds = 0; | ||
| function setAlarm() { | ||
| isPaused = false; | ||
| const pauseButton = document.getElementById("pause-button"); | ||
| if (pauseButton) { | ||
| pauseButton.removeAttribute("id"); | ||
| pauseButton.classList.add("unpause-alarm"); | ||
| pauseButton.addEventListener("click", pauseCountDown); | ||
| } | ||
|
|
||
| const alarmSetEl = document.getElementById("alarmSet"); | ||
| const timeRemainingEl = document.getElementById("timeRemaining"); | ||
| let totalSeconds = +alarmSetEl.value; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| remainingSeconds = totalSeconds; | ||
|
|
||
| if ( | ||
| totalSeconds <= 0 || | ||
| isNaN(totalSeconds) || | ||
| !Number.isInteger(totalSeconds) | ||
| ) { | ||
| alarmSetEl.value = ""; | ||
| return; | ||
| } | ||
| cleanInitialState(); | ||
|
|
||
| function updateCountDown() { | ||
| remainingSeconds = totalSeconds; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| let seconds = totalSeconds % 60; | ||
| let minutes = (totalSeconds - seconds) / 60; | ||
|
|
||
| let paddedSeconds = seconds.toString().padStart(2, "0"); | ||
| let paddedMinutes = minutes.toString().padStart(2, "0"); | ||
| timeRemainingEl.innerHTML = `Time Remaining: ${paddedMinutes}:${paddedSeconds}`; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (totalSeconds <= 0) { | ||
| document.body.classList.add("finish-countdown"); | ||
|
|
||
| playAlarm(); | ||
| clearInterval(intervalId); | ||
| return; | ||
| } | ||
|
|
||
| totalSeconds -= 1; | ||
| } | ||
|
|
||
| updateCountDown(); | ||
| intervalId = setInterval(updateCountDown, 1000); | ||
|
Comment on lines
+29
to
+33
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.
That is, function updateCountDown() {
...
}
function setAlarm() {
// Code to deal with input
...
remainingSeconds = totalSeconds; // Initialise the global countdown number
// Display the timer and start the countdown
updateCountDown();
intervalId = setInterval(updateCountDown, 1000);
} |
||
| } | ||
|
|
||
| function pauseCountDown(e) { | ||
| if (isPaused === false) { | ||
| clearInterval(intervalId); | ||
| e.target.textContent = "unpause"; | ||
| isPaused = true; | ||
| } else { | ||
| e.target.textContent = "Pause"; | ||
| isPaused = false; | ||
| intervalId = setInterval(() => { | ||
| if (remainingSeconds <= 0) { | ||
| clearInterval(intervalId); | ||
| return; | ||
| } | ||
| remainingSeconds -= 1; | ||
| const seconds = remainingSeconds % 60; | ||
| const minutes = (remainingSeconds - seconds) / 60; | ||
| const paddedSeconds = seconds.toString().padStart(2, "0"); | ||
| const paddedMinutes = minutes.toString().padStart(2, "0"); | ||
| document.getElementById("timeRemaining").innerHTML = | ||
| `Time Remaining: ${paddedMinutes}:${paddedSeconds}`; | ||
|
|
||
| if (remainingSeconds <= 0) { | ||
| document.body.classList.add("finish-countdown"); | ||
| playAlarm(); | ||
| clearInterval(intervalId); | ||
| } | ||
| }, 1000); | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| function cleanInitialState() { | ||
| clearInterval(intervalId); | ||
| document.body.classList.remove("finish-countdown"); | ||
| document.getElementById("timeRemaining").innerHTML = "Time Remaining: 00:00"; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| document.getElementById("alarmSet").value = null; | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
| pauseAlarm(); | ||
| } | ||
|
|
||
| // 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
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.
Uh oh!
There was an error while loading. Please reload this page.