-
-
Notifications
You must be signed in to change notification settings - Fork 321
London | 26-ITP-May | Dagim Daniel | Sprint 3 | Alarm clock #1331
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 all commits
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,65 @@ | ||
| function setAlarm() {} | ||
| const display = document.querySelector("#timeRemaining"); | ||
| const totalSeconds = document.querySelector("#alarmSet"); | ||
| const setButton = document.querySelector("#set"); | ||
| const stopButton = document.querySelector("#stop"); | ||
| let conuntdownInterval; | ||
|
|
||
| function formatTime(totalSeconds) { | ||
| const minutes = Math.floor(totalSeconds / 60); | ||
| const seconds = totalSeconds % 60; | ||
|
|
||
| const paddedMinutes = String(minutes).padStart(2, "0"); | ||
| const paddedSeconds = String(seconds).padStart(2, "0"); | ||
| return `Time Remaining: ${paddedMinutes}:${paddedSeconds}`; | ||
| } | ||
|
|
||
| function reset() { | ||
| clearInterval(conuntdownInterval); | ||
| display.textContent = "Time Remaining: 00:00"; | ||
| display.style.color = "black"; | ||
| setButton.disabled = false; | ||
| document.body.style.background = ""; | ||
| } | ||
| let countdownInterval; | ||
| setButton.addEventListener("click", () => { | ||
| let timeleft = Number(totalSeconds.value); | ||
|
cjyuan marked this conversation as resolved.
|
||
|
|
||
| if (timeleft <= 0 || isNaN(timeleft)) { | ||
| alert("please enter a number greater than zero (0)!"); | ||
| return; | ||
| } | ||
|
Comment on lines
+26
to
+31
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. What type of number should the input be? |
||
| setButton.disabled = true; | ||
|
|
||
| display.textContent = formatTime(timeleft); | ||
|
|
||
| const warningTime = 10; // seconds | ||
| clearInterval(conuntdownInterval); | ||
|
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. Is clearing If clearing it is necessary, then it is likely that we should also call |
||
|
|
||
| conuntdownInterval = setInterval(() => { | ||
| timeleft--; | ||
|
Comment on lines
+34
to
+40
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. New countdown implementation is good. You could consider moving the statement that displays the initial time on line 34 to just before line 39 so that the code in the function reads more like: |
||
|
|
||
| if (timeleft >= 0) { | ||
| display.textContent = formatTime(timeleft); | ||
| } | ||
|
|
||
| if (timeleft <= warningTime) { | ||
| display.style.color = "red"; | ||
| } | ||
|
|
||
| if (timeleft <= 0) { | ||
| clearInterval(conuntdownInterval); | ||
| document.body.style.backgroundColor = "grey"; | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
|
cjyuan marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| stopButton.addEventListener("click", () => { | ||
| clearInterval(conuntdownInterval); | ||
| reset(); | ||
| pauseAlarm(); | ||
| }); | ||
|
Comment on lines
+58
to
+62
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.
Normally if we could modify all the code, we could just update the original callback (lines 73-75). Since we are adding another onclick callback to |
||
|
|
||
| // 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.
Between this variable and the variable declared on line 6, one of them is not used and one of the them seems to be misspelled.