Skip to content

Commit 3b9b1e1

Browse files
fix review comments
1 parent 44bc9eb commit 3b9b1e1

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function formatTimeDisplay(seconds) {
2626
// =============> 0
2727

2828
// c) What is the return value of pad is called for the first time?
29-
// =============> 00
29+
// =============> "00"
3030

3131
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3232
// =============> 1. The remainder operator (%) returns the remainder left after dividing one number by another number. 61 % 60

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
function formatAs12HourClock(time) {
66
const hours = Number(time.slice(0, 2));
7-
const mins = time.slice(3, 5);
7+
const mins = time.slice(-2);
88
if (hours > 12) {
9-
return `${hours - 12}:${mins} pm`;
9+
return `${(hours - 12).toString().padStart(2, '0')}:${mins} pm`;
1010
}
1111
else if (hours == 0) {
12-
return `${hours + 12}:${mins} am`;
12+
return `12:${mins} am`;
1313
}
1414
else if (hours == 12) {
1515
return `${time} pm`;
@@ -31,23 +31,30 @@ console.assert(
3131
`current output: ${currentOutput2}, target output: ${targetOutput2}`
3232
);
3333

34-
const currentOutput3 = formatAs12HourClock("23:59");//
34+
const currentOutput3 = formatAs12HourClock("23:59");
3535
const targetOutput3 = "11:59 pm";
3636
console.assert(
3737
currentOutput3 === targetOutput3,
3838
`current output: ${currentOutput3}, target output: ${targetOutput3}`
3939
);
4040

41-
const currentOutput4 = formatAs12HourClock("00:00");//
41+
const currentOutput4 = formatAs12HourClock("00:00");
4242
const targetOutput4 = "12:00 am";
4343
console.assert(
4444
currentOutput4 === targetOutput4,
4545
`current output: ${currentOutput4}, target output: ${targetOutput4}`
4646
);
4747

48-
const currentOutput5 = formatAs12HourClock("12:00");//
48+
const currentOutput5 = formatAs12HourClock("12:00");
4949
const targetOutput5 = "12:00 pm";
5050
console.assert(
5151
currentOutput5 === targetOutput5,
5252
`current output: ${currentOutput5}, target output: ${targetOutput5}`
53+
);
54+
55+
const currentOutput6 = formatAs12HourClock("13:00");
56+
const targetOutput6 = "01:00 pm";
57+
console.assert(
58+
currentOutput6 === targetOutput6,
59+
`current output: ${currentOutput6}, target output: ${targetOutput6}`
5360
);

0 commit comments

Comments
 (0)