Skip to content

Commit c168e89

Browse files
authored
Correct time format in formatAs12HourClock function
Fixed time formatting to include minutes in 12-hour clock.
1 parent d8e4f7f commit c168e89

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ console.log(formatAs12HourClock("12:00"));
5555

5656
function formatAs12HourClock(time) {
5757
const hours = Number(time.slice(0, 2));
58-
58+
const minutes = time.slice(3);
59+
5960
if (hours === 12) {
6061
return `${time} pm`;
6162
}
6263

6364
if (hours > 12) {
64-
return `${hours - 12}:00 pm`;
65+
return `${hours - 12}:${minutes} pm`;
6566
}
6667
return `${time} am`;
6768
}
@@ -74,6 +75,8 @@ console.log(formatAs12HourClock("15:29"));
7475

7576
//Answer was 3:00pm, bug found.
7677

78+
//PS: fixed the bug by adding a seperate variable for minutes. Tested it again and it works now.
79+
7780

7881

7982

0 commit comments

Comments
 (0)