Skip to content
Closed
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
34 changes: 33 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
function setAlarm() {}
let countdownTimer;
let timeRemaining = 0;

function setAlarm() {
const input = document.getElementById("alarmSet");
timeRemaining = Number(input.value);

updateDisplay(timeRemaining);
clearInterval(countdownTimer);

countdownTimer = setInterval(function () {
timeRemaining--;

if (timeRemaining <= 0) {
clearInterval(countdownTimer);
updateDisplay(0);
playAlarm();
} else {
updateDisplay(timeRemaining);
}
}, 1000);
}
function updateDisplay(seconds) {

Choose a reason for hiding this comment

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

minor detail but the indentation for this updateDisplay function appears to be off. did you use the recommended formatter?

Choose a reason for hiding this comment

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

having said that, good implementation. moving forward, make sure to correctly format all of your code.

Copy link
Author

Choose a reason for hiding this comment

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

Will keep that in mind... Thank you

const heading = document.getElementById("timeRemaining");

const minutes = Math.floor(seconds / 60);
const secs = seconds % 60;

const minuteStr = String(minutes).padStart(2, '0');
const secondStr = String(secs).padStart(2, '0');

heading.innerText = `Time Remaining: ${minuteStr}:${secondStr}`;
}

// 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