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
39 changes: 38 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
function setAlarm() {}
function displayTime(time) {
const remainingElement = document.getElementById("timeRemaining");
const minutes = String(Math.floor(time / 60)).padStart(2, "0");
const seconds = String(time % 60).padStart(2, "0");
remainingElement.innerText = `Time Remaining: ${minutes}:${seconds}`;
}

let interval;

function setAlarm() {
let time = parseInt(document.getElementById("alarmSet").value);

if (!Number.isInteger(time) || time <= 0) {
return;
}

clearInterval(interval);
pauseAlarm();

displayTime(time);

interval = setInterval(() => {
time--;
displayTime(time);

if (time === 0) {
clearInterval(interval);
playAlarm();
}
}, 1000);
}

window.addEventListener("load", () => {
document.getElementById("stop").addEventListener("click", () => {
clearInterval(interval);
});
Comment on lines +34 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good touch.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjyuan I think i figured it out , the sound for the alarm wasn't stopping when the timer restarts, i have added pauseAlarm to solve that

});


// DO NOT EDIT BELOW HERE

Expand Down
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