Skip to content

Commit 2dd4f45

Browse files
committed
added a condition to handle hours between midnight and 1 am
1 parent 6c2f977 commit 2dd4f45

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,31 @@
55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
77
const minutes = time.slice(3);
8-
console.log(minutes);
8+
99
if (hours == 12) {
1010
return `${hours}:${minutes} pm`;
1111
}
1212

1313
if (hours > 12) {
1414
return `${hours - 12}:${minutes} pm`;
1515
}
16+
17+
if (hours === 0) {
18+
return `12:${minutes} am`;
19+
}
20+
1621
return `${time} am`;
1722
}
1823

19-
const currentOutput = formatAs12HourClock("08:00");
20-
const targetOutput = "08:00 am";
24+
const currentOutput = formatAs12HourClock("00:30");
25+
const targetOutput = "12:30 am";
2126
console.assert(
2227
currentOutput === targetOutput,
2328
`current output: ${currentOutput}, target output: ${targetOutput}`
2429
);
2530

26-
const currentOutput2 = formatAs12HourClock("23:00");
27-
const targetOutput2 = "11:00 pm";
31+
const currentOutput2 = formatAs12HourClock("13:01");
32+
const targetOutput2 = "1:01 pm";
2833
console.assert(
2934
currentOutput2 === targetOutput2,
3035
`current output: ${currentOutput2}, target output: ${targetOutput2}`

0 commit comments

Comments
 (0)