Skip to content

Commit 274d196

Browse files
committed
Add tests for 12:35, 01:01, and 13:01
1 parent 3d87510 commit 274d196

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
const minutes = time.slice(3, 5);
78
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
9+
return `${hours - 12}:${minutes} pm`;
910
}
1011
if (hours === 12) {
11-
return `${hours}:00 pm`;
12+
return `12:${minutes} pm`;
1213
}
1314
if (hours === 0) {
14-
const minutes = time.slice(3, 5);
1515
return `12:${minutes} am`;
1616
}
1717
return `${time} am`;
@@ -48,3 +48,21 @@ console.assert(
4848
currentOutput5 === targetOutput5,
4949
`current output: ${currentOutput5}, target output: ${targetOutput5}`
5050
);
51+
const currentOutput6 = formatAs12HourClock("12:35");
52+
const targetOutput6 = "12:35 pm";
53+
console.assert(
54+
currentOutput6 === targetOutput6,
55+
`current output: ${currentOutput6}, target output: ${targetOutput6}`
56+
);
57+
const currentOutput7 = formatAs12HourClock("01:01");
58+
const targetOutput7 = "01:01 am";
59+
console.assert(
60+
currentOutput7 === targetOutput7,
61+
`current output: ${currentOutput7}, target output: ${targetOutput7}`
62+
);
63+
const currentOutput8 = formatAs12HourClock("13:01");
64+
const targetOutput8 = "1:01 pm";
65+
console.assert(
66+
currentOutput8 === targetOutput8,
67+
`current output: ${currentOutput8}, target output: ${targetOutput8}`
68+
);

0 commit comments

Comments
 (0)