Skip to content

Commit 0772043

Browse files
committed
Update format time
1 parent 766e9b5 commit 0772043

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
if (hours === 0 || hours===24){
8+
return '12:00 am';
9+
}
10+
if (hours === 12){
11+
return `${hours}:00 pm`;
12+
}
713
if (hours > 12) {
814
return `${hours - 12}:00 pm`;
915
}
@@ -24,30 +30,22 @@ console.assert(
2430
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2531
);
2632
const currentOutput3 = formatAs12HourClock("00:00");
27-
const targetOutput3 = "00:00 am";
33+
const targetOutput3 = "12:00 am";
2834
console.assert(
2935
currentOutput3 === targetOutput3,
3036
`current output: ${currentOutput3}, target output: ${targetOutput3}`
3137
);
3238

3339
const currentOutput4 = formatAs12HourClock("24:00");
34-
const targetOutput4 = "12:00 pm";
40+
const targetOutput4 = "12:00 am";
3541
console.assert(
3642
currentOutput4 === targetOutput4,
3743
`current output: ${currentOutput4}, target output: ${targetOutput4}`
3844
);
3945

4046
const currentOutput5 = formatAs12HourClock("12:00");
41-
const targetOutput5 = "12:00 am";
47+
const targetOutput5 = "12:00 pm";
4248
console.assert(
4349
currentOutput5 === targetOutput5,
44-
`current output: ${currentOutput5}, target output: ${targetOutput}`
50+
`current output: ${currentOutput5}, target output: ${targetOutput5}`
4551
);
46-
47-
const currentOutput5 = formatAs12HourClock(":00");
48-
const targetOutput5 = "12:00 am";
49-
console.assert(
50-
currentOutput5 === targetOutput5,
51-
`current output: ${currentOutput5}, target output: ${targetOutput}`
52-
);
53-

0 commit comments

Comments
 (0)