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

// DO NOT EDIT BELOW HERE
function formatTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
}

function updateDisplay(seconds) {
document.getElementById("timeRemaining").textContent =
`Time Remaining: ${formatTime(seconds)}`;
}

function setAlarm() {
if (timer) {
clearInterval(timer);
}

let seconds = Number(document.getElementById("alarmSet").value);
updateDisplay(seconds);

timer = setInterval(() => {
seconds--;
updateDisplay(seconds);

if (seconds <= 0) {
clearInterval(timer);
playAlarm();
}
}, 1000);
}

// DO NOT EDIT BELOW HERE
var audio = new Audio("alarmsound.mp3");

function setup() {
Expand All @@ -22,4 +51,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