-
-
Notifications
You must be signed in to change notification settings - Fork 155
Sheffield | May-2025 | Hassan Osman | Alarm Clock App #602
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 6 commits
e7a0880
26d876a
dd250a3
82347f1
9175cb9
818aeec
c9113b1
b37fb9c
dea5f72
2c4bd8e
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,16 +1,64 @@ | ||
function setAlarm() {} | ||
let countdownInterval; | ||
|
||
function updateDisplay(seconds) { | ||
const timeDisplay = document.getElementById("timeRemaining"); | ||
const minutes = String(Math.floor(seconds / 60)).padStart(2, "0"); | ||
const remainingSeconds = String(seconds % 60).padStart(2, "0"); | ||
|
||
timeDisplay.textContent = `Time Remaining: ${minutes}:${remainingSeconds}`; | ||
} | ||
|
||
|
||
|
||
function setAlarm() { | ||
const input = document.getElementById("alarmSet"); | ||
let seconds = parseInt(input.value, 10); | ||
|
||
if (isNaN(seconds) || seconds <= 0 || input.value.trim() === "") { | ||
alert("Please enter a valid number!"); | ||
return; | ||
} | ||
|
||
|
||
clearInterval(countdownInterval); | ||
updateDisplay(seconds); | ||
|
||
countdownInterval = setInterval(() => { | ||
seconds--; | ||
|
||
if (seconds <= 0) { | ||
clearInterval(countdownInterval); | ||
updateDisplay(0); | ||
playAlarm(); | ||
document.body.style.backgroundColor = "red"; | ||
return; | ||
} | ||
|
||
updateDisplay(seconds); | ||
}, 1000); | ||
|
||
} | ||
|
||
document.getElementById("set").addEventListener("click", setAlarm); | ||
|
||
document.getElementById("stop").addEventListener("click", () => { | ||
clearInterval(countdownInterval); | ||
}); | ||
|
||
// DO NOT EDIT BELOW HERE | ||
|
||
var audio = new Audio("alarmsound.mp3"); | ||
var audio = new Audio("https://actions.google.com/sounds/v1/alarms/alarm_clock.ogg"); | ||
|
||
function setup() { | ||
document.getElementById("set").addEventListener("click", () => { | ||
setAlarm(); | ||
}); | ||
|
||
document.getElementById("stop").addEventListener("click", () => { | ||
clearInterval(countdownInterval); | ||
pauseAlarm(); | ||
document.body.style.backgroundColor = "white"; | ||
document.getElementById("timeRemaining").textContent = ""; | ||
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 the page is first loaded, the clock shows "Time Remaining: 00:00". You could also consider resetting the content to its "initial value" instead of clearing it. 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. All this time I thought you were referring to the input bos next to "set time to" LOL Anyway, this has now been sorted |
||
}); | ||
} | ||
|
||
|
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.
parseInt(" ")
orparseInt("")
returnNaN
, soinput.value.trim() === ""
is redundant.