-
-
Notifications
You must be signed in to change notification settings - Fork 219
West Midlands | 25-ITP-Sept | Baba Yusuf | Sprint 3 | Alarm Clock #891
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
Changes from all commits
11e30f5
3cb29a0
3d4c407
b235bd1
a4fcc54
5aa6e97
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,5 +1,41 @@ | ||
| function setAlarm() {} | ||
| let intervalId; | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| let time = Number(input.value); | ||
|
|
||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| clearInterval(intervalId); | ||
|
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. In addition to clearing |
||
|
|
||
| function format(num) { | ||
| if (num < 10) return "0" + num; | ||
| return num; | ||
| } | ||
|
Comment on lines
+11
to
+14
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. Why not just use |
||
|
|
||
| heading.innerText = | ||
| "Time Remaining: " + | ||
| format(Math.floor(time / 60)) + | ||
| ":" + | ||
| format(time % 60); | ||
|
|
||
| intervalId = setInterval(() => { | ||
| time--; | ||
|
|
||
| if (time <= 0) { | ||
| heading.innerText = "Time Remaining: 00:00"; | ||
| clearInterval(intervalId); | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
| heading.innerText = | ||
| "Time Remaining: " + | ||
| format(Math.floor(time / 60)) + | ||
| ":" + | ||
| format(time % 60); | ||
|
Comment on lines
+32
to
+36
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. This code is identical to those on lines 16-20 -- a hint that indicates we could simplify the code. |
||
| }, 1000); | ||
| } | ||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
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.
Can you think of any potential invalid input that you should prevent?