-
-
Notifications
You must be signed in to change notification settings - Fork 319
London | 26-ITP-May | Bisrat Tesfay | Sprint 3 | Alarmclock #1330
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,37 @@ | ||
| function setAlarm() {} | ||
| let timer; | ||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| let seconds = Number(input.value); | ||
|
|
||
| const timeRemaining = document.getElementById("timeRemaining"); | ||
|
|
||
| clearInterval(timer); | ||
|
|
||
| function updateDisplay() { | ||
|
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. Good job putting the code for formatting into an own function. This makes it reusable and easier to change the formatting if needed |
||
| const minutes = Math.floor(seconds / 60); | ||
| const remainingSeconds = seconds % 60; | ||
|
|
||
| const formattedTime = | ||
| String(minutes).padStart(2, "0") + | ||
| ":" + | ||
| String(remainingSeconds).padStart(2, "0"); | ||
|
|
||
| timeRemaining.textContent = `Time Remaining: ${formattedTime}`; | ||
| } | ||
|
|
||
| updateDisplay(); | ||
|
|
||
| timer = setInterval(() => { | ||
| if (seconds > 0) { | ||
| seconds--; | ||
| updateDisplay(); | ||
| } else { | ||
| clearInterval(timer); | ||
| playAlarm(); | ||
| document.body.style.backgroundColor = "red"; | ||
|
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. The color stays red when the timer is restarted. How can you change this? |
||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
|
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. Nice stylings. This makes the page look nicer |
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 happens when seconds are 0 or negative?