Skip to content

Commit 6a98e1c

Browse files
committed
Change case and add check to avoid negative numbers input
1 parent a2d1980 commit 6a98e1c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎Sprint-3/alarmclock/alarmclock.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const oneSecondInMilliseconds = 1000;
21
const lengthOfAlarmSound = 20000;
32

43
let timeLeft;
@@ -15,7 +14,8 @@ function setAlarm() {
1514

1615
// validate result
1716
const result = parseInt(timeLeft);
18-
if (isNaN(result)) {
17+
console.log(result);
18+
if (isNaN(result) || result < 0) {
1919
return;
2020
}
2121

@@ -41,14 +41,14 @@ function updateTimer() {
4141

4242
// give a time in seconds
4343
function formatTime(seconds) {
44-
minutes = Math.floor(seconds / 60);
44+
const minutes = Math.floor(seconds / 60);
4545
seconds = seconds % 60;
4646

47-
const seconds_padded = String(seconds).padStart(2, "0");
48-
const minutes_paddded = String(minutes).padStart(2, "0");
47+
const secondsPadded = String(seconds).padStart(2, "0");
48+
const minutesPaddded = String(minutes).padStart(2, "0");
4949

50-
const formatted_seconds = `Time Remaining: ${minutes_paddded}:${seconds_padded}`;
51-
return formatted_seconds;
50+
const formattedPeconds = `Time Remaining: ${minutesPaddded}:${secondsPadded}`;
51+
return formattedPeconds;
5252
}
5353

5454
function stopAlarm() {

0 commit comments

Comments
 (0)