Skip to content

Commit 9f55f62

Browse files
committed
Fix 12-hour clock conversion and add edge-case tests
1 parent 86827f4 commit 9f55f62

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎Sprint-3/5-stretch-extend/format-time.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ function formatAs12HourClock(time) {
1111
if (hours >= 12) {
1212
suffix = "pm";
1313
}
14+
1415
let formattedHours = hours % 12;
1516

1617
if (formattedHours === 0) {
1718
formattedHours = 12;
1819
}
20+
1921
return `${formattedHours}:${minutes} ${suffix}`;
2022
}
2123

@@ -32,6 +34,7 @@ console.assert(
3234
currentOutput2 === targetOutput2,
3335
`current output: ${currentOutput2}, target output: ${targetOutput2}`,
3436
);
37+
3538
const noonOutput = formatAs12HourClock("12:00");
3639
const noonTarget = "12:00 pm";
3740
console.assert(
@@ -45,4 +48,11 @@ console.assert(
4548
midnightOutput === midnightTarget,
4649
`current output: ${midnightOutput}, target output: ${midnightTarget}`,
4750
);
48-
console.log("All tests passed");
51+
52+
const minuteOutput = formatAs12HourClock("13:05");
53+
const minuteTarget = "01:05 pm";
54+
console.assert(
55+
minuteOutput === minuteTarget,
56+
`current output: ${minuteOutput}, target output: ${minuteTarget}`,
57+
);
58+
console.log("all tests passed");

0 commit comments

Comments
 (0)