Skip to content

Commit 584bd1d

Browse files
committed
Fixed all inconsistencies, alarm clock works
1 parent 036886f commit 584bd1d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Sprint-3/alarmclock/alarmclock.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
let countdownInterval = null;
22
let secondsLeft = 0;
3+
const heading = document.getElementById("timeRemaining");
34

45
function setAlarm() {
5-
// Read the number of minutes from the input field (expects minutes)
6+
// Read the number of seconds from the input field
67
const input = document.getElementById("alarmSet");
7-
const minutes = parseInt(input.value, 10);
8+
const seconds = parseInt(input.value, 10);
89

910
// If nothing useful was entered, do nothing
10-
if (isNaN(minutes) || minutes <= 0) {
11+
if (isNaN(seconds) || seconds <= 0) {
1112
return;
1213
}
1314

14-
// Store the remaining time; currently this value is in minutes (not seconds yet)
15-
secondsLeft = minutes;
16-
15+
// Use seconds directly
16+
secondsLeft = seconds;
1717
// Stop any existing countdown
1818
if (countdownInterval !== null) {
1919
clearInterval(countdownInterval);
@@ -46,11 +46,8 @@ function setAlarm() {
4646
function updateTimeDisplay() {
4747
const minutes = Math.floor(secondsLeft / 60);
4848
const seconds = secondsLeft % 60;
49-
5049
const displayMin = minutes.toString().padStart(2, "0");
5150
const displaySec = seconds.toString().padStart(2, "0");
52-
53-
const heading = document.getElementById("timeRemaining");
5451
heading.textContent = `Time Remaining: ${displayMin}:${displaySec}`;
5552
}
5653

0 commit comments

Comments
 (0)