Skip to content

Commit 42a5ebc

Browse files
committed
complete timeConverter.js ex
1 parent 4c0993b commit 42a5ebc

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
function formatAs12HourClock(time) {
2-
32
const hours = Number(time.slice(0, 2));
3+
const minutes = time.slice(3);
4+
if (hours === 0) {
5+
return `12:${minutes} am`;
6+
}
47

8+
if (hours === 12) {
9+
return `${time} pm`;
10+
}
511
if (hours > 12) {
6-
return `${hours - 12}:00 pm`;
12+
return `${hours - 12}:${minutes} pm`;
713
}
814
return `${time} am`;
915
}
1016

11-
export {formatAs12HourClock};
17+
export { formatAs12HourClock };

0 commit comments

Comments
 (0)