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
43 changes: 42 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
function setAlarm() {}
let isCountingDown = false;

function setAlarm() {
const timeSubmitted = document.getElementById("alarmSet").value;
const message = document.getElementById("reminder");
let totalSeconds = Number(timeSubmitted);

if (totalSeconds <= 0 || Number.isInteger(totalSeconds) === false) {
return (message.textContent =
"Value of time should be integer and more than '0'.");
}

if (isCountingDown === true) {
return (message.textContent =
"Alarm is counting down. Pressing 'set alarm' is disallowed.");
}

message.textContent = "";
function updateDisplay() {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
const minutesInString = String(minutes).padStart(2, "0");
const secondsInString = String(seconds).padStart(2, "0");

document.getElementById("timeRemaining").textContent =
`Time Remaining: ${minutesInString}:${secondsInString}`;
}

updateDisplay(totalSeconds);
isCountingDown = true;

const countdownId = setInterval(() => {
totalSeconds -= 1;
updateDisplay(totalSeconds);

if (totalSeconds <= 0) {
clearInterval(countdownId);
playAlarm();
isCountingDown = false;
}
}, 1000);
Comment on lines +32 to +41

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If Set Alarm is clicked again before this interval finishes, what happens to the countdown created here?

To "like" or "dislike" this comment, please follow this link

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 is one of the important edge cases. Please look into this.

}

// DO NOT EDIT BELOW HERE

Expand Down
5 changes: 3 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<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">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />
<p id="reminder" style="color: red"></p>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We were trying to do something here, I guess. What was the chain of thought?

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.

I don't understand what it means

@shashwatksingh shashwatksingh Nov 27, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm asking about the reason for the change.

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.

This line is for showing the reminder of non-integer value submission and re-pressing "set alarm" during counting down.


<button id="set" type="button">Set Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
Expand Down