Skip to content

Commit 808359a

Browse files
fixed formatting for "hour"
1 parent 31b4ae8 commit 808359a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ function formatAs12HourClock(time) {
1111
if (hours === 12) {
1212
return `12:${minutes} pm`;
1313
}
14+
1415
if (hours > 12) {
15-
return `${hours - 12}:${minutes} pm`;
16+
let paddedHours = String(hours - 12).padStart(2, "0");
17+
return `${paddedHours}:${minutes} pm`;
1618
}
1719
return `${time} am`;
1820
}
@@ -52,9 +54,9 @@ console.assert(
5254
`current output: ${currentOutput5}, target output: ${targetOutput5}`
5355
);
5456

55-
const currentOutput6= formatAs12HourClock("12:45");
56-
const targetOutput6= "12:45 pm";
57+
const currentOutput6 = formatAs12HourClock("12:45");
58+
const targetOutput6 = "12:45 pm";
5759
console.assert(
5860
currentOutput6 === targetOutput6,
5961
`current output: ${currentOutput6}, target output: ${targetOutput6}`
60-
);
62+
);

0 commit comments

Comments
 (0)