Skip to content

Commit 70fd1a0

Browse files
Completed sprint-2/5 stretch-extend
1 parent 3d31d1b commit 70fd1a0

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
8+
if (hours === 0) {
9+
return `12:00 am`;
10+
}
11+
12+
if (hours === 12) {
13+
return `12:00 pm`;
14+
}
15+
716
if (hours > 12) {
817
return `${hours - 12}:00 pm`;
918
}
19+
1020
return `${time} am`;
1121
}
1222

@@ -23,3 +33,18 @@ console.assert(
2333
currentOutput2 === targetOutput2,
2434
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2535
);
36+
37+
38+
const currentOutput3 = formatAs12HourClock("12:00");
39+
const targetOutput3 = "12:00 pm";
40+
console.assert(
41+
currentOutput3 === targetOutput3,
42+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
43+
);
44+
45+
const currentOutput4 = formatAs12HourClock("00:00");
46+
const targetOutput4 = "12:00 am";
47+
console.assert(
48+
currentOutput4 === targetOutput4,
49+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
50+
);

0 commit comments

Comments
 (0)