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
38 changes: 37 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
function setAlarm() {}
let intervalId;

function setAlarm() {
const input = document.getElementById("alarmSet");
let time = Number(input.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you think of any potential invalid input that you should prevent?


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

clearInterval(intervalId);
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to clearing intervalId, can you think of anything else that should also be reset before a new countdown starts?


function format(num) {
if (num < 10) return "0" + num;
return num;
}
Comment on lines +11 to +14
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just use String.prototype.padStart()?


heading.innerText =
"Time Remaining: " +
format(Math.floor(time / 60)) +
":" +
format(time % 60);

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

if (time <= 0) {
heading.innerText = "Time Remaining: 00:00";
clearInterval(intervalId);
playAlarm();
return;
}

heading.innerText =
"Time Remaining: " +
format(Math.floor(time / 60)) +
":" +
format(time % 60);
Comment on lines +32 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

This code is identical to those on lines 16-20 -- a hint that indicates we could simplify the code.

}, 1000);
}
// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");
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
2 changes: 1 addition & 1 deletion Sprint-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.6.1",
"jest": "^30.0.4",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.0.4"
}
}
Loading