File tree Expand file tree Collapse file tree
Sprint-2/5-stretch-extend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55function formatAs12HourClock ( time ) {
66 const hours = Number ( time . slice ( 0 , 2 ) ) ;
7+
8+ if ( hours === 0 ) {
9+ return `12:00 am` ;
10+ }
11+
12+ if ( hours === 12 ) {
13+ return `12:00 pm` ;
14+ }
15+
716 if ( hours > 12 ) {
817 return `${ hours - 12 } :00 pm` ;
918 }
19+
1020 return `${ time } am` ;
1121}
1222
@@ -23,3 +33,18 @@ console.assert(
2333 currentOutput2 === targetOutput2 ,
2434 `current output: ${ currentOutput2 } , target output: ${ targetOutput2 } `
2535) ;
36+
37+
38+ const currentOutput3 = formatAs12HourClock ( "12:00" ) ;
39+ const targetOutput3 = "12:00 pm" ;
40+ console . assert (
41+ currentOutput3 === targetOutput3 ,
42+ `current output: ${ currentOutput3 } , target output: ${ targetOutput3 } `
43+ ) ;
44+
45+ const currentOutput4 = formatAs12HourClock ( "00:00" ) ;
46+ const targetOutput4 = "12:00 am" ;
47+ console . assert (
48+ currentOutput4 === targetOutput4 ,
49+ `current output: ${ currentOutput4 } , target output: ${ targetOutput4 } `
50+ ) ;
You can’t perform that action at this time.
0 commit comments