-
-
Notifications
You must be signed in to change notification settings - Fork 195
West Midlands | 25-ITP-Sept | Mustaf Asani | Sprint 3 | Feature/alarmclock #921
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?
Conversation
Sprint-3/alarmclock/alarmclock.js
Outdated
| if (timer) { | ||
| clearInterval(timer); | ||
| timer = null; | ||
| } |
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.
You may also want to stop the alarm (to reset all application states before starting a new countdown)
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.
added code to stop the alarm if it was playing
Sprint-3/alarmclock/alarmclock.js
Outdated
| clearInterval(timer); | ||
| timer = null; | ||
| } | ||
| timer = setInterval(countDown, 1000); |
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.
Line 20 will still get executed even when inputTime is 0.
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.
removed redundant code
| if (inputTime === 10) { | ||
| changeBgColor = true; | ||
| } else if (inputTime === 0) { | ||
| displayTime(inputTime); | ||
| playAlarm(); | ||
| document.querySelector("#alarmSet").reset(); | ||
| } | ||
| displayTime(inputTime); | ||
| if (typeof audio !== "undefined" && audio) { | ||
| audio.pause(); | ||
| try { | ||
| audio.currentTime = 0; | ||
| } catch (e) {} | ||
| audio.loop = false; // disable looping if it was set | ||
| } | ||
| if (timer) { | ||
| clearInterval(timer); | ||
| } | ||
| timer = setInterval(countDown, 1000); | ||
| } |
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.
When inputTime is 0, can you identify all the code between line 11 and 30 that will be executed? And among them, which code are unnecessarily executed?
Consider organising the code in the following maner:
// Step 1: Reset everything (timer, audio, background, ...) before starting a new countdown
// Note: Can also consider implement a function to reset everything and then call the function here
...
// Step 2; Validate input
...
// Step 3: Start a new countdown depending on the value of `inputTime`
...
Learners, PR Template
Self checklist
Changelist
Added functions to alarm to make the timer count down from input time and alarm to off when it reaches 0.