-
-
Notifications
You must be signed in to change notification settings - Fork 283
Birmingham | 26-ITP-Jan | Tasleem Adedokun | Sprint 3 | Alarm clock #1093
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 5 commits
9e994c5
2adcc6f
3161e3a
942d94d
f269468
f0641bb
4a8d0b2
5a8b6dd
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,51 @@ | ||
| function setAlarm() {} | ||
| let interval; | ||
| let timeRemaining = 0; | ||
| let flashInterval; | ||
|
|
||
| function setAlarm() { | ||
| clearInterval(interval); | ||
| clearInterval(flashInterval); | ||
|
|
||
| const input = document.getElementById("alarmSet"); | ||
| const display = document.getElementById("timeRemaining"); | ||
|
|
||
| timeRemaining = parseInt(input.value); | ||
|
|
||
| if (isNaN(timeRemaining) || timeRemaining <= 0) return; | ||
| updateDisplay(); | ||
|
|
||
| interval = setInterval(() => { | ||
| if (timeRemaining <= 0) { | ||
| clearInterval(interval); | ||
| timeRemaining = 0; | ||
| updateDisplay(); | ||
| playAlarm(); | ||
|
|
||
| // Start flashing background | ||
| if (window.JEST_WORKER_ID){ | ||
| flashInterval = setInterval(() => { | ||
| document.body.style.backgroundColor = | ||
| document.body.style.backgroundColor === "green" ? "white" : "green"; | ||
| }, 500); | ||
|
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 tested the work locally and the background colour is not changing when the timer reaches 00:00. Could you look into it?
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.
worked on it already thanks. 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, the background is flashing now! Great job on completing the stretch task! 🎉 |
||
|
|
||
| return; // exit interval | ||
| }} | ||
| // Decrement only if above 0 | ||
| timeRemaining--; | ||
| 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. When testing, the timer reaches stops at -1:-1 rather than 00:00. Could you look into it?
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 think it should be fine now.
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. Thank you very much for your time. 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. Working as expected now 👍 |
||
| }, 1000); | ||
|
|
||
| function updateDisplay() { | ||
| const minutes = Math.floor(timeRemaining / 60); | ||
| const seconds = timeRemaining % 60; | ||
|
|
||
| const mm = String(minutes).padStart(2, "0"); | ||
| const ss = String(seconds).padStart(2, "0"); | ||
|
|
||
| display.textContent = `Time Remaining: ${mm}:${ss}`; | ||
| } | ||
|
Comment on lines
+48
to
+56
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 logic looks good. 👍
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.
Thank you very much. |
||
| } | ||
|
|
||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Make an Alarm Clock | ||
| #Make an Alarm Clock | ||
|
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. Was this intended? You can test the markdown here.
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.
no it wasn't intended fixed. |
||
|
|
||
| In this folder you will find the basic setup of an alarm clock. | ||
|
|
||
|
|
||
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 this needed?