Skip to content

London | 25-ITP-May | Khilola Rustamova | Sptint-3| Alarm Clock #636

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
function setAlarm() {}
let intervalId;
let currentTime = 0; // Store the remaining time for pause/resume

function setAlarm() {
currentTime = parseInt(document.getElementById("alarmSet").value);
if (isNaN(currentTime) || currentTime <= 0) return;

updateTimeDisplay();

intervalId = setInterval(() => {
currentTime--;
updateTimeDisplay();

if (currentTime <= 0) {
clearInterval(intervalId);
playAlarm();
}
}, 1000);
}

function updateTimeDisplay() {
let minutes = String(Math.floor(currentTime / 60)).padStart(2, '0');
let seconds = String(currentTime % 60).padStart(2, '0');
document.getElementById("timeRemaining").innerText = `Time Remaining: ${minutes}:${seconds}`;
}

function stopAlarm() {
clearInterval(intervalId); // Stop the countdown
currentTime = 0; // Reset time
updateTimeDisplay(); // Update display to 00:00
audio.pause(); // Stop alarm sound
audio.currentTime = 0; // Reset sound to start
document.body.style.backgroundColor = ""; // Reset background
}

function pauseAlarm() {
clearInterval(intervalId);
audio.pause();
audio.currentTime = 0; // Rewind
document.body.style.backgroundColor = ""; // Reset background
}

function resetAlarm() {
clearInterval(intervalId);
currentTime = 0;
updateTimeDisplay();
audio.pause();
audio.currentTime = 0;
document.body.style.backgroundColor = "";
}

// DO NOT EDIT BELOW HERE

Expand All @@ -10,16 +59,24 @@ function setup() {
});

document.getElementById("stop").addEventListener("click", () => {
stopAlarm();
});

document.getElementById("reset").addEventListener("click", () => {
resetAlarm();
});

document.getElementById("pause").addEventListener("click", () => {
pauseAlarm();
});
}

function playAlarm() {
audio.play();
document.body.style.backgroundColor = "red"; // Change background
}

function pauseAlarm() {
audio.pause();
}



window.onload = setup;
4 changes: 3 additions & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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>
<title>"Alarm clock app"</title>
</head>
<body>
<div class="centre">
Expand All @@ -14,6 +14,8 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>

<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
<button id="pause" type="button">Pause Alarm</button>
<button id="reset" type="button">Reset Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0",
"jest": "^29.2.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.2.2"
},
"jest": {
Expand Down
Loading