-
-
Notifications
You must be signed in to change notification settings - Fork 281
Glasgow| 26-ITP-JAN |Alasdair MacDonald | Sprint 3 | Alarm Clock #1039
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 all commits
7f63885
b5c66ef
b9165a5
82e848d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. parseInt(input)
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. Thanks for the feedback! I’ve made the following updates:
Let me know if there’s anything else I can improve. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,47 @@ | ||
| function setAlarm() {} | ||
| let countdown; | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
| function startTimer(input) { | ||
| const display = document.getElementById("timeRemaining"); | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
| // Validate input | ||
| const timeRemaining = Number(input); | ||
|
|
||
| function setup() { | ||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
| if (isNaN(timeRemaining) || timeRemaining <= 0) { | ||
| display.textContent = "Please enter a valid number"; | ||
| return; | ||
| } | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| }); | ||
| } | ||
| let remaining = timeRemaining; | ||
|
|
||
| function playAlarm() { | ||
| audio.play(); | ||
| } | ||
| // Clear any previous timer | ||
| clearInterval(countdown); | ||
|
|
||
| function updateDisplay() { | ||
| const minutes = Math.floor(remaining / 60); | ||
| const seconds = remaining % 60; | ||
|
|
||
| display.textContent = `Time Remaining: ${String(minutes).padStart( | ||
| 2, | ||
| "0" | ||
| )}:${String(seconds).padStart(2, "0")}`; | ||
| } | ||
|
|
||
| function pauseAlarm() { | ||
| audio.pause(); | ||
| // Show initial time | ||
| updateDisplay(); | ||
|
|
||
| countdown = setInterval(() => { | ||
| remaining--; | ||
|
|
||
| updateDisplay(); | ||
|
|
||
| if (remaining <= 0) { | ||
| clearInterval(countdown); | ||
| playAlarm(); | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| window.onload = setup; | ||
| // :white_check_mark: Fix missing function | ||
| function playAlarm() { | ||
| alert("Time's up!"); | ||
| } |
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.