File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Sprint-2/5-stretch-extend Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change 44
55function formatAs12HourClock ( time ) {
66 const hours = Number ( time . slice ( 0 , 2 ) ) ;
7+ const minutes = time . slice ( 3 , 5 ) ;
8+ if ( hours === 0 ) {
9+ return `12:${ minutes } am` ;
10+ }
11+ if ( hours === 12 ) {
12+ return `12:${ minutes } pm` ;
13+ }
714 if ( hours > 12 ) {
8- return `${ hours - 12 } :00 pm` ;
15+ return `${ String ( hours - 12 ) . padStart ( 2 , "0" ) } : ${ minutes } pm` ;
916 }
1017 return `${ time } am` ;
1118}
1219
1320
14- const currentOutput = formatAs12HourClock ( "08:00" ) ;
15- const targetOutput = "08:00 am" ;
16- console . assert (
17- currentOutput === targetOutput ,
18- `Expected ${ targetOutput } but got ${ currentOutput } `
19- ) ;
21+
22+ // Tests
23+ console . log ( formatAs12HourClock ( "08:00" ) ) ;
24+ console . log ( formatAs12HourClock ( "15:45" ) ) ;
25+ console . log ( formatAs12HourClock ( "12:00" ) ) ;
26+ console . log ( formatAs12HourClock ( "00:00" ) ) ;
2027
You can’t perform that action at this time.
0 commit comments