Skip to content
Open
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
38 changes: 36 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
function setAlarm() {}
function setAlarm() {
const input = document.getElementById("alarmSet").value;

if (!input || input <= 0) {
alert("Please enter a valid number");
return;
}

let timeRemaining = parseInt(input);
const display = document.getElementById("timeRemaining");

// Show initial time
display.textContent = `Time Remaining: 00:${timeRemaining
.toString()
.padStart(2, "0")}`;

// Clear any previous timer
clearInterval(countdown);

countdown = setInterval(() => {
timeRemaining--;

display.textContent = `Time Remaining: 00:${timeRemaining
.toString()
.padStart(2, "0")}`;

if (timeRemaining === 0) {
clearInterval(countdown);
playAlarm();
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

let countdown; // 👈 needed for timer control

var audio = new Audio("alarmsound.mp3");

function setup() {
Expand All @@ -20,6 +53,7 @@ function playAlarm() {

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

window.onload = setup;
window.onload = setup;
Loading