Skip to content

Commit 32e9c02

Browse files
author
Ogbemi mene
committed
my code to fix the bug
1 parent ba8e540 commit 32e9c02

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7+
const minutes = time.slice(3, 5);
8+
79
if (hours > 12) {
8-
return `${hours - 12}:00 pm`;
10+
const convertedHours = hours - 12;
11+
// Pad the hour with a leading zero if it's a single digit (e.g., 3 becomes "03")
12+
const paddedHours = String(convertedHours).padStart(2, "0");
13+
return `${paddedHours}:${minutes} pm`;
914
}
15+
1016
return `${time} am`;
1117
}
1218

19+
// === Your Tests (All will now pass silently!) ===
20+
1321
const currentOutput = formatAs12HourClock("08:00");
1422
const targetOutput = "08:00 am";
1523
console.assert(
@@ -23,3 +31,11 @@ console.assert(
2331
currentOutput2 === targetOutput2,
2432
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2533
);
34+
35+
console.assert(formatAs12HourClock("15:00") === "03:00 pm", `Failed Case D: 03:00 pm`);
36+
console.assert(formatAs12HourClock("13:00") === "01:00 pm", `Failed Case E: 01:00 pm`);
37+
console.assert(formatAs12HourClock("15:45") === "03:45 pm", `Failed Case D: 03:45 pm`);
38+
console.assert(formatAs12HourClock("13:45") === "01:45 pm", `Failed Case E: 01:45 pm`);
39+
console.assert(formatAs12HourClock("08:45") === "08:45 am", `Failed Case F: 08:45 am`);
40+
41+
console.log("All current assertions completed!");

0 commit comments

Comments
 (0)