File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Sprint-2/5-stretch-extend Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ console.assert(
6262
6363function formatAs12HourClock ( time ) {
6464 let hours = Number ( time . slice ( 0 , 2 ) ) ;
65- const minutes = time . slice ( 3 ) ;
65+ const minutes = time . slice ( - 2 ) ;
6666
6767 let suffix ;
6868 if ( hours >= 12 ) {
@@ -71,7 +71,11 @@ function formatAs12HourClock(time) {
7171 suffix = "am" ;
7272 }
7373
74- hours = hours % 12 || 12 ; // convert 0 to 12, 13 to 1
74+ hours = hours % 12 || 12 ; // convert 0 to 12, 13 to 1 it returns the remainder
75+ // for eg. taking 12/12 the remainder is 0
76+ // similarly if 13 is taken 13/12 , the remainder is 1, the operator || helps us to return the remainder after
77+ // a division
78+
7579 const formattedHours = hours . toString ( ) . padStart ( 2 , "0" ) ;
7680
7781 return `${ formattedHours } :${ minutes } ${ suffix } ` ;
@@ -84,3 +88,6 @@ console.assert(
8488 currentOutput6 === targetOutput6 ,
8589 `current output: ${ currentOutput6 } , target output: ${ targetOutput6 } `
8690)
91+
92+
93+ // Updated const minutes = time.slice(3) --- to const minutes = time.slice(-2)
You can’t perform that action at this time.
0 commit comments