Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
26 changes: 25 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
function setAlarm() {}
const title = document.querySelector('title')
title.textContent = "Alarm clock app";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why did you undo the change where you changed the title in the HTML first?

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.

Thanks for the feedback. I originally changed the title via the DOM to practice DOM manipulation, but I’ve now updated it in the HTML file to match the requirements.

function time_convert(num) {
let minutes = Math.floor((num % 3600) / 60);
let seconds = num % 60;
return minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0');
}
function setAlarm() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens when a user clicks the set alarm button while the countdown is already running?

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.

Thanks for the feedback. Function has now been updated to stop multiple timers

const alarmSetInputEl = document.getElementById("alarmSet");
let timeEl = Number(alarmSetInputEl.value);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens if the user enters a negative number or a non number string?

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.

Thanks for the feedback, Function now updated to validate input.

const timeRemainingCounterEl = document.getElementById("timeRemaining");
const interval = setInterval(() => {
timeEl--;

timeRemainingCounterEl.textContent = `Time Remaining: ${time_convert(timeEl)}`;

if (timeEl <= 0) {
clearInterval(interval);
timeRemainingCounterEl.textContent = "Done!";
playAlarm();
}
}, 1000);
}


// DO NOT EDIT BELOW HERE

Expand All @@ -23,3 +46,4 @@ function pauseAlarm() {
}

window.onload = setup;

1 change: 1 addition & 0 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
<script src="alarmclock.js"></script>
</body>
</html>

Loading