-
-
Notifications
You must be signed in to change notification settings - Fork 193
West Midlands | ITP-Sept-2025 | Ali Naru | Sprint 3 | Alarm Clock #880
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 2 commits
074067e
cae8413
49f886a
a602e02
ff9dad0
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,46 @@ | ||
| function setAlarm() {} | ||
| const heading = document.getElementById("timeRemaining"); | ||
| const input = document.getElementById("alarmSet"); | ||
| const setBtn = document.getElementById("set"); | ||
|
|
||
| let remaining = 0; | ||
| let intervalId = null; | ||
|
|
||
| function format(seconds) { | ||
| const minute = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
| const second = String(seconds % 60).padStart(2, "0"); | ||
| return `${m}:${s}`; | ||
| } | ||
|
|
||
| function updateHeading() { | ||
| heading.textContent = `Time Remaining: ${format(remaining)}`; | ||
| } | ||
|
|
||
| function tick() { | ||
| if (remaining <= 0) { | ||
| clearInterval(intervalId); | ||
| intervalId = null; | ||
| updateHeading(); | ||
| if (typeof window.playAlarm === "function") { | ||
| window.playAlarm(); | ||
| } | ||
| return; | ||
| } | ||
| remaining -= 1; | ||
| updateHeading(); | ||
| } | ||
|
|
||
| function setAlarm() { | ||
| const value = parseInt(input.value, 10); | ||
| // Guard clause: ignore invalid or non-positive input | ||
| if (!Number.isFinite(value) || value <= 0) return; | ||
| if (intervalId) clearInterval(intervalId); | ||
| remaining = value; | ||
| updateHeading(); | ||
| intervalId = setInterval(tick, 1000); | ||
|
||
| } | ||
|
|
||
| setBtn.addEventListener("click", setAlarm); | ||
| updateHeading(); | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.