-
-
Notifications
You must be signed in to change notification settings - Fork 283
LONDON | MAY 2025 | JESUS DEL MORAL | SPRINT3 | ALARM CLOCK #671
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 all commits
f622d48
d23f10a
712efa4
92881f4
b41e30b
7cc8268
f641ff3
49aeb27
3886e8c
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,12 +1,68 @@ | ||
| function setAlarm() {} | ||
| const timeSetup = document.querySelector("#alarmSet"); | ||
| const timeCountdown = document.querySelector("#timeRemaining"); | ||
| let countdownInterval; | ||
|
|
||
| // Shared display update function | ||
| function updateDisplay(seconds) { | ||
| const minutes = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
| const secs = String(seconds % 60).padStart(2, "0"); | ||
| timeCountdown.innerText = `Time Remaining: ${minutes}:${secs}`; | ||
| } | ||
|
|
||
|
|
||
| function parsePositiveInteger(value) { | ||
| if (typeof value !== "string") return null; | ||
| const trimmed = value.trim(); | ||
|
|
||
| // Check if it's all digits (no letters or symbols) | ||
| if (!/^\d+$/.test(trimmed)) return null; | ||
|
|
||
| const num = Number(trimmed); | ||
| return num > 0 ? num : null; | ||
|
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. I think |
||
| } | ||
|
|
||
| function setAlarm() { | ||
| const totalSeconds = parsePositiveInteger(timeSetup.value); | ||
|
|
||
| if (totalSeconds === null) { | ||
| timeCountdown.innerText = "Please enter a valid number of seconds."; | ||
|
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. Did you ever see your app displaying ""Please enter a valid number of seconds."? (If not, it may imply the code is not needed) What does the function If you combine the code in
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 modified setalarm(), where the function will call updateDisplay().... I commited the last changes.... I am struggling to changes made in the previous commit in order to remove the quote generator files... I will ask for help on Saturday to a volunteer |
||
| document.body.style.backgroundColor = ""; | ||
| return; | ||
| } | ||
|
|
||
| startCountdown(totalSeconds); // Start the countdown timer | ||
| document.body.style.backgroundColor = ""; | ||
|
|
||
| } | ||
|
|
||
| function startCountdown(totalSeconds) { | ||
| clearInterval(countdownInterval); // Stop previous countdown | ||
| updateDisplay(totalSeconds); // Show first tick immediately | ||
|
|
||
| countdownInterval = setInterval(() => { | ||
| totalSeconds--; | ||
|
|
||
| if (totalSeconds <= 0) { | ||
| clearInterval(countdownInterval); | ||
| timeCountdown.innerText = "Time's up!"; | ||
| document.body.style.backgroundColor = "#ff4c4c"; | ||
| playAlarm(); | ||
| return; | ||
| } | ||
|
|
||
| updateDisplay(totalSeconds); | ||
| }, 1000); | ||
| } | ||
|
|
||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| setAlarm(); // Sets the initial time display | ||
| //startCountdown(); // Starts the actual countdown | ||
| }); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
|
|
@@ -15,11 +71,11 @@ function setup() { | |
| } | ||
|
|
||
| function playAlarm() { | ||
| audio.play(); | ||
| audio.play(); // Play the alarm sound | ||
| } | ||
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| audio.pause(); // Stop the alarm sound | ||
| } | ||
|
|
||
| window.onload = setup; | ||
| window.onload = setup; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <link rel="stylesheet" href="style.css" /> | ||
| <title>Title here</title> | ||
| </head> | ||
| <body> | ||
| <div class="centre"> | ||
| <h1 id="timeRemaining">Time Remaining: 00:00</h1> | ||
| <label for="alarmSet">Set time to: </label> | ||
| <input id="alarmSet" type="number" min="0"/> | ||
|
|
||
| <button id="set" type="button">Set Alarm</button> | ||
| <button id="stop" type="button">Stop Alarm</button> | ||
| </div> | ||
| <script src="alarmclock.js"></script> | ||
| </body> | ||
| </html> |
Uh oh!
There was an error while loading. Please reload this page.