Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 34 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
function setAlarm() {}
function setAlarm() {
let time = Number(document.getElementById("alarmSet").value);
const heading = document.getElementById("timeRemaining");

audio.loop = true;

document.body.style.backgroundColor = "";

function updateDisplay(t) {
const minutes = String(Math.floor(t / 60)).padStart(2, "0");
const seconds = String(t % 60).padStart(2, "0");
heading.innerText = `Time Remaining: ${minutes}:${seconds}`;
}

Choose a reason for hiding this comment

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

Good use of modularity to extract updateDisplay behaviour. Could this sit outside of the setAlarm function to further decouple the functions?

Copy link
Author

Choose a reason for hiding this comment

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

@Poonam-raj i did that .


updateDisplay(time);

const intervalId = setInterval(() => {
time--;

if (time <= 0) {
clearInterval(intervalId);
updateDisplay(0);

document.body.style.backgroundColor = "red";

playAlarm();

} else {
updateDisplay(time);
}
}, 1000);
}


// DO NOT EDIT BELOW HERE

Expand All @@ -22,4 +54,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