Skip to content

Commit ca40d0c

Browse files
committed
completed 5-stretch-extend
1 parent 2ef3cb2 commit ca40d0c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ function formatAs12HourClock(time) {
77
if (hours > 12) {
88
return `${hours - 12}:00 pm`;
99
}
10+
if (hours === 0) {
11+
return `${12}:00 am`;
12+
}
1013
return `${time} am`;
1114
}
15+
console.log("formatAs12HourClock",formatAs12HourClock("17:00"))
1216

1317
const currentOutput = formatAs12HourClock("08:00");
1418
const targetOutput = "08:00 am";
@@ -23,3 +27,34 @@ console.assert(
2327
currentOutput2 === targetOutput2,
2428
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2529
);
30+
31+
const currentOutput3 = formatAs12HourClock("00:00");
32+
const targetOutput3 = "12:00 am";
33+
console.assert(
34+
currentOutput3 === targetOutput3,
35+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
36+
);
37+
38+
const currentOutput4 = formatAs12HourClock("00:00");
39+
const targetOutput4 = "12:00 pm";
40+
console.assert(
41+
currentOutput4 === targetOutput4,
42+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
43+
);
44+
45+
const currentOutput5 = formatAs12HourClock("20:30");
46+
const targetOutput5 = "08:30 am";
47+
console.assert(
48+
currentOutput5 === targetOutput5,
49+
`current output: ${currentOutput5}, target output: ${targetOutput5}`
50+
);
51+
52+
const currentOutput6 = formatAs12HourClock("23:55");
53+
const targetOutput6 = "11:55 am";
54+
console.assert(
55+
currentOutput6 === targetOutput6,
56+
`current output: ${currentOutput6}, target output: ${targetOutput6}`
57+
);
58+
// test mid-day
59+
// test 08:30
60+
// test 11:55

0 commit comments

Comments
 (0)