Skip to content

Commit bfe65da

Browse files
author
Enice-Codes
committed
completed errors
1 parent 26dd684 commit bfe65da

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.
44
;
55
function formatAs12HourClock(time) {
6-
const hours = Number(time.slice(0, 2));
7-
const minutes = time.slice(3, 5);
8-
if (h)
6+
const [hourString, minutes] = time.split(":");
7+
const hours = Number(hourString);
98

109
if (hours === 0) {
1110
return `12:${minutes} am`;
@@ -15,11 +14,11 @@ function formatAs12HourClock(time) {
1514
return `12:${minutes} pm`;
1615
}
1716

18-
if (hours > 12) {
19-
return `${hours - 12}:${minutes} pm`;
17+
if (hours < 12) {
18+
return `${hours}:${minutes} am`;
2019
}
2120

22-
return `${time} am`;
21+
return `${hours - 12}:${minutes} pm`;
2322
}
2423

2524
// Existing tests

0 commit comments

Comments
 (0)