-
-
Notifications
You must be signed in to change notification settings - Fork 283
West Midlands | 25-ITP-Sep | Baba Yusuf | Sprint 3 | Alarm Clock #900
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 7 commits
11e30f5
3cb29a0
3d4c407
b235bd1
a4fcc54
5aa6e97
80cc2eb
50a0653
9a76928
6948ee0
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); | ||
|
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 if the user inputs
Author
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. will review, update based on the above comments and revert by tomorrow morning. many thanks for for your guidance. |
||
|
|
||
| const heading = document.getElementById("timeRemaining"); | ||
|
|
||
| clearInterval(intervalId); | ||
|
|
||
| function format(num) { | ||
| if (num < 10) return "0" + num; | ||
| return num; | ||
| } | ||
|
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 is nice way to pad number, is there any predefined methods?
Author
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. ... i have now changed to code to use padStart instead of format()
Comment on lines
+24
to
+51
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. Some input that can mess up the clock display can still pass this check. |
||
|
|
||
| heading.innerText = | ||
| "Time Remaining: " + | ||
| format(Math.floor(time / 60)) + | ||
| ":" + | ||
| format(time % 60); | ||
|
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. You are repeating this twice in your code, how would you increase efficiency if you needed to change something in the future?
Author
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. I can hold the value in/as a variable so I can call the variable without having to repeat an expression or an existing value.
Author
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. To cater for invalid entry (include negative values), I am now implemented a form of input validation to ensure the user enters a valid positive number. 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. Hi @Baba05206 , wouldn't it be easy to create a utility function, that takes arguments like |
||
|
|
||
| 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); | ||
| }, 1000); | ||
|
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. These
Author
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. Replaced magic numbers with named constants that explains their purpose. |
||
| } | ||
| // 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.
Is the variable readable, time (is it hour, minute, second, milliseconds)?
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.
now, i believe it is. i had thought it did, but now certainly does. thanks