-
-
Notifications
You must be signed in to change notification settings - Fork 324
London | May-2026-itp | Vitalii Kmit | Sprint 3 | Alarm clock #1366
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
Vitalii-code
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
Vitalii-code: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.
+72
−3
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3a1925a
Set up looping alarm
Vitalii-code d79612d
Revert the previous change for index.html
Vitalii-code 1e6f60f
Add setTimout and setInterval
Vitalii-code a2d1980
Remove setTimout to pass all tests
Vitalii-code 6a98e1c
Change case and add check to avoid negative numbers input
Vitalii-code d53501a
Check if whole number
Vitalii-code 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,73 @@ | ||
| function setAlarm() {} | ||
| const lengthOfAlarmSound = 20000; | ||
|
|
||
| let timeLeft; | ||
| let intervalID; | ||
| let timeoutID; | ||
| let display; | ||
|
|
||
| function setAlarm() { | ||
| stopAlarm(); | ||
|
|
||
| // set up time | ||
| timeLeft = document.getElementById("alarmSet").value; | ||
| display = document.getElementById("timeRemaining"); | ||
|
|
||
| // validate result | ||
| const result = parseInt(timeLeft); | ||
| console.log(result); | ||
| if (isNaN(result) || result < 0 || !Number.isInteger(result)) { | ||
|
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 integer validation doesn't seem to be working as expected. What value or type is being passed to Number.isInteger()? result stores the validated input, but is it being used anywhere after the validation? |
||
| return; | ||
| } | ||
|
|
||
| display.textContent = formatTime(timeLeft); | ||
|
|
||
| if (!intervalID) { | ||
| intervalID = setInterval(updateTimer, 1000); | ||
| } | ||
|
|
||
| console.log(`Alarm set for ${timeLeft} seconds`); | ||
| } | ||
|
|
||
| function updateTimer() { | ||
| timeLeft = timeLeft - 1; | ||
|
|
||
| display.textContent = formatTime(timeLeft); | ||
|
|
||
| if (timeLeft <= 0) { | ||
| alarmFinished(); | ||
| cleanUp(); | ||
| } | ||
| } | ||
|
|
||
| // give a time in seconds | ||
| function formatTime(seconds) { | ||
| const minutes = Math.floor(seconds / 60); | ||
| seconds = seconds % 60; | ||
|
|
||
| const secondsPadded = String(seconds).padStart(2, "0"); | ||
| const minutesPaddded = String(minutes).padStart(2, "0"); | ||
|
|
||
| const formattedPeconds = `Time Remaining: ${minutesPaddded}:${secondsPadded}`; | ||
| return formattedPeconds; | ||
| } | ||
|
|
||
| function stopAlarm() { | ||
| pauseAlarm(); | ||
| cleanUp(); | ||
| } | ||
|
|
||
| function cleanUp() { | ||
| clearInterval(intervalID); | ||
| clearTimeout(timeoutID); | ||
| timeoutID = null; | ||
| intervalID = null; | ||
| } | ||
|
|
||
| function alarmFinished() { | ||
| audio.loop = true; | ||
| playAlarm(); | ||
| console.log("Alarm finished"); | ||
| } | ||
|
|
||
| // 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
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.
What would happen if I set the alarm for -10 seconds?