Skip to content

Commit 45bd5ef

Browse files
author
russom
committed
more edge cases added. Assertion has failed. If condition inside the function needs fixing.
1 parent 313ea73 commit 45bd5ef

1 file changed

Lines changed: 49 additions & 2 deletions

File tree

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

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
77
if (hours > 12) {
88
return `${hours - 12}:00 pm`;
9-
}
10-
return `${time} am`;
9+
} else if (hours === 12) {
10+
return `${hours}:00 pm`;
11+
} else if (hours === 0) {
12+
return `12:00 am`;
13+
} else if (hours < 12) {
14+
return `${time} am`;
15+
} else return `${time} am`;
1116
}
1217

1318
const currentOutput = formatAs12HourClock("08:00");
@@ -23,3 +28,45 @@ console.assert(
2328
currentOutput2 === targetOutput2,
2429
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2530
);
31+
32+
const currentOutput3 = formatAs12HourClock("00:00");
33+
const targetOutput3 = "12:00 am";
34+
console.assert(
35+
currentOutput3 === targetOutput3,
36+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
37+
);
38+
39+
const currentOutput4 = formatAs12HourClock("12:00");
40+
const targetOutput4 = "12:00 pm";
41+
console.assert(
42+
currentOutput4 === targetOutput4,
43+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
44+
);
45+
46+
const currentOutput5 = formatAs12HourClock("00:01");
47+
const targetOutput5 = "12:01 am";
48+
console.assert(
49+
currentOutput5 === targetOutput5,
50+
`current output: ${currentOutput5}, target output: ${targetOutput5}`
51+
);
52+
53+
const currentOutput6 = formatAs12HourClock("12:01");
54+
const targetOutput6 = "12:01 pm";
55+
console.assert(
56+
currentOutput6 === targetOutput6,
57+
`current output: ${currentOutput6}, target output: ${targetOutput6}`
58+
);
59+
60+
const currentOutput7 = formatAs12HourClock("23:59");
61+
const targetOutput7 = "11:59 pm";
62+
console.assert(
63+
currentOutput7 === targetOutput7,
64+
`current output: ${currentOutput7}, target output: ${targetOutput7}`
65+
);
66+
67+
const currentOutput8 = formatAs12HourClock("13:00");
68+
const targetOutput8 = "01:00 pm";
69+
console.assert(
70+
currentOutput8 === targetOutput8,
71+
`current output: ${currentOutput8}, target output: ${targetOutput8}`
72+
);

0 commit comments

Comments
 (0)