Skip to content

Commit 096632e

Browse files
committed
correcting padStart for minutes String
1 parent 5733d12 commit 096632e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function formatAs12HourClock(time) {
1818
throw new Error("Invalid time");
1919
}
2020

21-
const minutesStr = String(minutes).padEnd(2, 0);
21+
const minutesStr = String(minutes).padStart(2, 0);
2222

2323
if (hours == 0) {
2424
return `12:${minutesStr} am`;
@@ -39,15 +39,15 @@ function formatAs12HourClock(time) {
3939
return `${time} am`;
4040
}
4141

42-
const currentOutput = formatAs12HourClock("08:00");
43-
const targetOutput = "08:00 am";
42+
const currentOutput = formatAs12HourClock("08:01");
43+
const targetOutput = "08:01 am";
4444
console.assert(
4545
currentOutput === targetOutput,
4646
`current output: ${currentOutput}, target output: ${targetOutput}`
4747
);
4848

49-
const currentOutput2 = formatAs12HourClock("23:00");
50-
const targetOutput2 = "11:00 pm";
49+
const currentOutput2 = formatAs12HourClock("23:09");
50+
const targetOutput2 = "11:09 pm";
5151
console.assert(
5252
currentOutput2 === targetOutput2,
5353
`current output: ${currentOutput2}, target output: ${targetOutput2}`
@@ -102,6 +102,15 @@ console.assert(
102102
`current output: ${currentOutput9}, target output: ${targetOutput9}`
103103
);
104104

105+
const currentOutput10 = formatAs12HourClock("24:05");
106+
const targetOutput10 = "12:05 am";
107+
console.assert(
108+
currentOutput10 === targetOutput10,
109+
`current output: ${currentOutput10}, target output: ${targetOutput10}`
110+
);
111+
112+
// Edge cases and invalid inputs
113+
105114
try {
106115
formatAs12HourClock("25:00");
107116
console.assert(false, "Expected an error for invalid hours");

0 commit comments

Comments
 (0)