Skip to content

Commit be15364

Browse files
committed
minutes recognition added, exercice 5 Done
1 parent c8fe831 commit be15364

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
function formatAs12HourClock(time) {
66
let hours = time.slice(0, 2);
7+
let minutes= time.slice(3, 5);
8+
79
if (Number(hours) > 12) {
810
hours = String(hours - 12);
911
hours = hours.padStart(2, "0");
1012

11-
return `${hours}:00 pm`;
13+
return `${hours}:${minutes} pm`;
1214
}
13-
return `${time} am`;
15+
return `${hours}:${minutes} am`;
1416
}
1517

1618
let currentOutput = formatAs12HourClock("14:00");
@@ -27,22 +29,22 @@ console.assert(
2729
`current output: ${currentOutput}, target output: ${targetOutput}`
2830
);
2931
//==========================
30-
currentOutput = formatAs12HourClock("07:00");
31-
targetOutput = "07:00 am";
32+
currentOutput = formatAs12HourClock("07:51");
33+
targetOutput = "07:51 am";
3234
console.assert(
3335
currentOutput === targetOutput,
3436
`current output: ${currentOutput}, target output: ${targetOutput}`
3537
);
3638
//==========================
37-
currentOutput = formatAs12HourClock("00:00");
38-
targetOutput = "00:00 am";
39+
currentOutput = formatAs12HourClock("00:37");
40+
targetOutput = "00:37 am";
3941
console.assert(
4042
currentOutput === targetOutput,
4143
`current output: ${currentOutput}, target output: ${targetOutput}`
4244
);
4345
//==========================
44-
currentOutput = formatAs12HourClock("20:00");
45-
targetOutput = "08:00 pm";
46+
currentOutput = formatAs12HourClock("20:59");
47+
targetOutput = "08:59 pm";
4648
console.assert(
4749
currentOutput === targetOutput,
4850
`current output: ${currentOutput}, target output: ${targetOutput}`

0 commit comments

Comments
 (0)