Skip to content

Commit 44bc9eb

Browse files
completed_5-stretch-extend
1 parent 86fdc2d commit 44bc9eb

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

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

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
const mins = time.slice(3, 5);
78
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
9+
return `${hours - 12}:${mins} pm`;
10+
}
11+
else if (hours == 0) {
12+
return `${hours + 12}:${mins} am`;
13+
}
14+
else if (hours == 12) {
15+
return `${time} pm`;
916
}
1017
return `${time} am`;
1118
}
@@ -23,3 +30,24 @@ console.assert(
2330
currentOutput2 === targetOutput2,
2431
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2532
);
33+
34+
const currentOutput3 = formatAs12HourClock("23:59");//
35+
const targetOutput3 = "11:59 pm";
36+
console.assert(
37+
currentOutput3 === targetOutput3,
38+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
39+
);
40+
41+
const currentOutput4 = formatAs12HourClock("00:00");//
42+
const targetOutput4 = "12:00 am";
43+
console.assert(
44+
currentOutput4 === targetOutput4,
45+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
46+
);
47+
48+
const currentOutput5 = formatAs12HourClock("12:00");//
49+
const targetOutput5 = "12:00 pm";
50+
console.assert(
51+
currentOutput5 === targetOutput5,
52+
`current output: ${currentOutput5}, target output: ${targetOutput5}`
53+
);

0 commit comments

Comments
 (0)