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
31 changes: 30 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
function setAlarm() {}
let remainingSeconds = 0;
let intervalId;

function formatTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60).toString().padStart(2, "0");
const seconds = Math.floor(totalSeconds % 60).toString().padStart(2, "0");
return `${minutes}:${seconds}`;
}
function setAlarm() {
clearInterval(intervalId);

const initialSeconds = Number(document.getElementById("alarmSet").value);
const timeRemainingHeading = document.getElementById("timeRemaining");
if (!initialSeconds || initialSeconds <= 0) {
timeRemainingHeading.innerText = "Please enter a positive number of seconds";
return;
}
Comment on lines +14 to +17

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This code is not matching the standard for formatting. (Indendation inside the brackets). How can you ensure consistent formatting of all your code?

remainingSeconds = initialSeconds;

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 I start the alarm with 0 seconds or a negative value?

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.

Checked for 0, negative or empty input.


timeRemainingHeading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;

intervalId = setInterval(() => {
remainingSeconds--;
timeRemainingHeading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
if (remainingSeconds === 0) {
clearInterval(intervalId);
playAlarm();
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
3 changes: 2 additions & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<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>
<script defer src="scripts.js"></script>
</head>
<body>
<div class="centre">
Expand Down
Loading