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 6 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 lengthOfAlarmSound = 20000; | ||
|
|
||
| let timeLeft; | ||
| let intervalID; | ||
| let timeoutID; | ||
| 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); | ||
| 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 | ||
|
|
||
|
|
||
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.
Is this variable being used anywhere? If not, can it be removed?