There was an error while loading. Please reload this page.
1 parent 4bc9f9f commit a6b3a00Copy full SHA for a6b3a00
1 file changed
Sprint-2/5-stretch-extend/format-time.js
@@ -4,14 +4,15 @@
4
5
function formatAs12HourClock(time) {
6
const hours = Number(time.slice(0, 2));
7
+ const minutes = Number(time.slice(3, 5)).toString().padStart(2, "0");
8
if (hours === 0 || hours === 24) {
- return `12:${time.slice(3, 5)} am`;
9
+ return `12:${minutes} am`;
10
} else if (hours > 12) {
- return `${(hours - 12).toString().padStart(2, "0")}:${time.slice(3, 5)} pm`;
11
+ return `${(hours - 12).toString().padStart(2, "0")}:${minutes} pm`;
12
} else if (hours < 12) {
- return `${time.slice(0, 2)}:${time.slice(3, 5)} am`;
13
+ return `${hours.toString().padStart(2, "0")}:${minutes} am`;
14
} else {
- return `${time.slice(0, 2)}:${time.slice(3, 5)} pm`;
15
+ return `${hours.toString().padStart(2, "0")}:${minutes} pm`;
16
}
17
18
0 commit comments