-
-
Notifications
You must be signed in to change notification settings - Fork 283
Birmingham | ITP-Jan | Roman Sanaye | Sprint 3 | Alarm-clock #1080
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 3 commits
15c47ae
5935fcb
c4446ac
a6783da
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,95 @@ | ||
| function setAlarm() {} | ||
| // DOM elements | ||
| const setAlarmBtn = document.getElementById("set"); | ||
| const stopAlarmBtn = document.getElementById("stop"); | ||
| const timeRemaining = document.getElementById("timeRemaining"); | ||
| let alarmInterval; | ||
| let totalSeconds; | ||
|
|
||
| // reset function - returns app to clean initial state | ||
| function resetAlarm() { | ||
| function resetToInitialState() { | ||
| totalSeconds = 0; | ||
| timeRemaining.innerText = "Time Remaining: 00:00"; | ||
| document.getElementById("alarmSet").value = ""; | ||
| stopAlarmBtn.style.display = "none"; | ||
| setAlarmBtn.style.display = "inline-block"; // ADD THIS - show set button | ||
| } | ||
|
|
||
| function stopSound() { | ||
| if (typeof pauseAlarm === "function") { | ||
| pauseAlarm(); | ||
| } | ||
| } | ||
|
cjyuan marked this conversation as resolved.
|
||
| // Clear any running interval | ||
| if (alarmInterval) { | ||
| clearInterval(alarmInterval); | ||
| alarmInterval = null; | ||
| } | ||
|
|
||
| resetToInitialState(); | ||
| stopSound(); | ||
| } | ||
|
|
||
| // Set Alarm function | ||
| function setAlarm() { | ||
| const input = document.getElementById("alarmSet"); | ||
| const timeValue = parseInt(input.value); | ||
| const hasActiveTimer = alarmInterval !== null; | ||
|
|
||
| function updateDisplay() { | ||
| let minutes = Math.floor(totalSeconds / 60); | ||
| let seconds = totalSeconds % 60; | ||
| timeRemaining.innerText = `Time Remaining: ${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`; | ||
| } | ||
|
cjyuan marked this conversation as resolved.
Outdated
|
||
|
|
||
| function startTimer() { | ||
| alarmInterval = setInterval(() => { | ||
| if (totalSeconds > 0) { | ||
|
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. Why check if |
||
| totalSeconds--; | ||
| updateDisplay(); | ||
| if (totalSeconds === 0) { | ||
| clearInterval(alarmInterval); | ||
| alarmInterval = null; | ||
|
|
||
| // WHEN ALARM STARTS: hide set button, show only stop button | ||
| setAlarmBtn.style.display = "none"; | ||
| stopAlarmBtn.style.display = "inline-block"; | ||
|
|
||
| playAlarm(); | ||
| } | ||
| } | ||
| }, 1000); | ||
| } | ||
|
|
||
| resetAlarm(); | ||
|
|
||
| if (isNaN(timeValue) || timeValue <= 0) { | ||
| if (!hasActiveTimer) alert("Please enter a number greater than 0"); | ||
| return; | ||
| } | ||
|
|
||
| totalSeconds = timeValue; | ||
| stopAlarmBtn.style.display = "inline-block"; | ||
| setAlarmBtn.style.display = "inline-block"; // Ensure set button is visible | ||
| updateDisplay(); | ||
| startTimer(); | ||
| } | ||
|
|
||
| // DO NOT EDIT BELOW HERE | ||
|
|
||
| var audio = new Audio("alarmsound.mp3"); | ||
|
|
||
| function setup() { | ||
| // Ensure clean initial state when page loads | ||
| resetAlarm(); | ||
|
|
||
| document.getElementById("set").addEventListener("click", () => { | ||
| setAlarm(); | ||
| }); | ||
|
|
||
| document.getElementById("stop").addEventListener("click", () => { | ||
| pauseAlarm(); | ||
| resetAlarm(); | ||
|
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. Should you need to avoid modifying the code beyond the marker you can use |
||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| // jest.setup.js | ||
| require("@testing-library/jest-dom/extend-expect"); |
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.
Could also consider
visibility: hidden(suggestion: look up the difference betweendisplay: noneandvisibility: falsedisabledproperty(No change required)