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

function showTime() {
const minutes = Math.floor(timeLeft / 60);
const seconds = timeLeft % 60;

const formattedMinutes = String(minutes).padStart(2, "0");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

love this well done!

const formattedSeconds = String(seconds).padStart(2, "0");

const text = formattedMinutes + ":" + formattedSeconds;
document.getElementById("timeRemaining").textContent =
"Time Remaining: " + text;
}

function setAlarm() {
clearInterval(timer);

const input = document.getElementById("alarmSet").value;
if (input.trim() === "") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

very interesting way of checking this!! Unusual but not bad!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

very interesting way of checking this!! Unusual but not bad!

return;
}
timeLeft = Number(input);
if (
timeLeft <= 0 ||
!Number.isFinite(timeLeft) ||
!Number.isInteger(timeLeft)
) {
alert("Please enter a positive whole number.");
return;
}
showTime();

timer = setInterval(() => {
timeLeft = timeLeft - 1;
showTime();

if (timeLeft === 0) {
clearInterval(timer);
timer = null;
playAlarm();
}
}, 1000);
}

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