Repository navigation
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
3a1925a
d79612d
1e6f60f
a2d1980
6a98e1c
d53501a
512d598
0117596
41568f2
5a04895
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,73 @@ | ||
| function setAlarm() {} | ||
| const oneSecondInMilliseconds = 1000; | ||
| const lengthOfAlarmSound = 20000; | ||
|
|
||
| let timeLeft; | ||
| let intervalID; | ||
| let timeoutID; | ||
|
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. Is this variable being used anywhere? If not, can it be removed? |
||
| let display; | ||
|
|
||
| function setAlarm() { | ||
| stopAlarm(); | ||
|
|
||
| // set up time | ||
| timeLeft = document.getElementById("alarmSet").value; | ||
|
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. What would happen if I set the alarm for -10 seconds? |
||
| display = document.getElementById("timeRemaining"); | ||
|
|
||
| // validate result | ||
| const result = parseInt(timeLeft); | ||
| if (isNaN(result)) { | ||
| 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) { | ||
| minutes = Math.floor(seconds / 60); | ||
|
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. is minutes supposed to be a global variable? |
||
| seconds = seconds % 60; | ||
|
|
||
| const seconds_padded = String(seconds).padStart(2, "0"); | ||
|
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. Does the variable naming convention match style guide? |
||
| const minutes_paddded = String(minutes).padStart(2, "0"); | ||
|
|
||
| const formatted_seconds = `Time Remaining: ${minutes_paddded}:${seconds_padded}`; | ||
| return formatted_seconds; | ||
| } | ||
|
|
||
| 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 | ||
|
|
||
|
|
||
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.
These variables are declared but don't appear to be used anywhere. Are they still needed, or can they be removed to keep the code cleaner?