-
-
Notifications
You must be signed in to change notification settings - Fork 327
Birmingham | 26-ITP-May | Gabriel Pawuoi | Sprint 3 | Implement alarmclock #1412
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,24 @@ | ||
| function setAlarm() {} | ||
| function setAlarm() { | ||
| let seconds = parseInt(document.getElementById("alarmSet").value, 10); | ||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| function formatTime(s) { | ||
|
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. formatTime gets rebuilt every time setAlarm runs. |
||
| const mins = String(Math.floor(s / 60)).padStart(2, "0"); | ||
| const secs = String(s % 60).padStart(2, "0"); | ||
| return `Time Remaining: ${mins}:${secs}`; | ||
| } | ||
|
|
||
| heading.innerText = formatTime(seconds); | ||
|
|
||
| const timer = setInterval(() => { | ||
|
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. Set a 10 second alarm and then few seconds later set a 30 second one without refreshing. Watch the heading closely. What is happening, and what does const timer being declared inside setAlarm have to do with it? |
||
| seconds--; | ||
| heading.innerText = formatTime(seconds); | ||
| if (seconds <= 0) { | ||
| clearInterval(timer); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // 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.
What does parseInt("", 10) give you? Try clicking Set Alarm with the box empty and watch the heading and then think about whether seconds <= 0 on line 16 will ever be true.