-
-
Notifications
You must be signed in to change notification settings - Fork 201
Manchester| 25-ITP-Sep| Fithi Teklom| Sprint 3 | Alarm Clock #908
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 4 commits
8085c0c
b3ad0d8
d33934f
9c3ee51
bffd4b4
7ded280
c9aa8f1
0b85c7a
e618de2
76f1971
b6af9d4
fc92b97
0c30fdd
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,89 @@ | ||
| function setAlarm() {} | ||
|
|
||
|
|
||
| // function setAlarm() {} | ||
|
|
||
| let timeLeft = 0; | ||
| let timer = null; | ||
| let flashing = null; | ||
|
|
||
| // DOM references | ||
| window.addEventListener("DOMContentLoaded", () => { | ||
| // const display = document.getElementById("timeRemaining"); | ||
| const setButton = document.getElementById("set"); | ||
| const stopButton = document.getElementById("stop"); | ||
|
|
||
| // Event listeners | ||
| // if (setButton) setButton.addEventListener("click", () => playAlarm()); | ||
| if (stopButton) stopButton.addEventListener("click", stopAlarm); | ||
cjyuan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Show 00:00 on load | ||
| updateDisplay(0); | ||
| }); | ||
|
|
||
| // ------------------------------- | ||
| // FUNCTIONS | ||
| // ------------------------------- | ||
|
|
||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet").value; | ||
| const parsed = parseInt(input, 10); | ||
|
|
||
| if (isNaN(parsed) || parsed < 0) return; | ||
|
||
|
|
||
| timeLeft = parsed; | ||
|
|
||
| // Update display immediately | ||
| updateDisplay(timeLeft); | ||
|
|
||
| // Clear previous countdown | ||
| clearInterval(timer); | ||
|
|
||
cjyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Start countdown every 1000ms | ||
| timer = setInterval(() => { | ||
| if (timeLeft > 0) { | ||
| timeLeft--; | ||
| updateDisplay(timeLeft); | ||
| } | ||
|
|
||
| if (timeLeft === 0) { | ||
| clearInterval(timer); | ||
| startAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
||
|
|
||
| function updateDisplay(seconds) { | ||
| const mins = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
| const secs = String(seconds % 60).padStart(2, "0"); | ||
|
|
||
| const display = document.getElementById("timeRemaining"); | ||
| if (!display) return; | ||
| display.textContent = `Time Remaining: ${mins}:${secs}`; | ||
| } | ||
|
|
||
| function startAlarm() { | ||
| playAlarm(); | ||
|
|
||
| // Flashing background | ||
| if (!flashing){ | ||
| flashing = setTimeout(() => { | ||
| document.body.style.backgroundColor = | ||
| document.body.style.backgroundColor === "red" ? "orange" : "red"; | ||
| }, 300); | ||
| } | ||
| } | ||
|
|
||
| function stopAlarm() { | ||
| if (typeof pauseAlarm === "function") pauseAlarm(); | ||
|
|
||
| clearInterval(flashing); | ||
| flashing = null; | ||
| document.body.style.backgroundColor = ""; | ||
| } | ||
|
|
||
|
|
||
| // module.exports= setAlarm; | ||
|
|
||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| testEnvironment: "jsdom", | ||
| verbose: true, | ||
| testMatch: ["**/*.test.js"], | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.