Skip to content
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
37 changes: 35 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,37 @@
function setAlarm() {}
let countdown = null;

function setAlarm() {
let secondsLeft = parseInt(document.getElementById("alarmSet").value, 10);
const timeDisplay = document.getElementById("timeRemaining");

if (isNaN(secondsLeft) || secondsLeft <= 0) {
timeDisplay.innerText = "Time Remaining: 00:00";
return;
}

if (countdown !== null) {
clearInterval(countdown);
}

const updateDisplay = (time) => {
let minutes = Math.floor(time / 60).toString().padStart(2, "0");
let seconds = (time % 60).toString().padStart(2, "0");
timeDisplay.innerText = "Time Remaining: " + minutes + ":" + seconds;
};

updateDisplay(secondsLeft);

countdown = setInterval(() => {
secondsLeft = secondsLeft - 1;
updateDisplay(secondsLeft);

if (secondsLeft <= 0) {
clearInterval(countdown);
countdown = null;
playAlarm();
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand All @@ -22,4 +55,4 @@ function pauseAlarm() {
audio.pause();
}

window.onload = setup;
window.onload = setup;
2 changes: 1 addition & 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 Down
Loading