Skip to content

Commit 0d5ad45

Browse files
committed
wrote tests for any edge cases and fixed resulting bugs
1 parent 742c228 commit 0d5ad45

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
const minutes = time.slice(3);
8+
console.log(minutes);
9+
if (hours == 12) {
10+
return `${hours}:${minutes} pm`;
11+
}
12+
713
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
14+
return `${hours - 12}:${minutes} pm`;
915
}
1016
return `${time} am`;
1117
}
@@ -23,3 +29,17 @@ console.assert(
2329
currentOutput2 === targetOutput2,
2430
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2531
);
32+
33+
const currentOutput3 = formatAs12HourClock("23:30");
34+
const targetOutput3 = "11:30 pm";
35+
console.assert(
36+
currentOutput3 === targetOutput3,
37+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
38+
);
39+
40+
const currentOutput4 = formatAs12HourClock("12:01");
41+
const targetOutput4 = "12:01 pm";
42+
console.assert(
43+
currentOutput4 === targetOutput4,
44+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
45+
);

0 commit comments

Comments
 (0)