Skip to content

Commit dcb29c3

Browse files
committed
Fix handling of midnight of formatAs12HourClock function
1 parent 4d85df1 commit dcb29c3

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function formatAs12HourClock(time) {
88
const hours = Number(time.slice(0, 2));
99
const minutes = time.slice(3, 5);
1010

11-
if (hours === 0) {
11+
if (hours === 0 || hours === 24) {
1212
return `12:${minutes} am`;
1313
}
1414
else if (hours > 12) {
@@ -47,4 +47,11 @@ const targetOutput4 = "12:00 pm";
4747
console.assert(
4848
currentOutput4 === targetOutput4,
4949
`current output: ${currentOutput4}, target output: ${targetOutput4}`
50+
);
51+
52+
const currentOutput5 = formatAs12HourClock("24:00");
53+
const targetOutput5 = "12:00 am";
54+
console.assert(
55+
currentOutput5 === targetOutput5,
56+
`current output: ${currentOutput5}, target output: ${targetOutput5}`
5057
);

0 commit comments

Comments
 (0)