File tree Expand file tree Collapse file tree
Sprint-3/5-stretch-extend Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828// my code:
2929function formatAs12HourClock ( time ) {
3030 const hours = Number ( time . slice ( 0 , 2 ) ) ;
31- if ( hours >= 12 ) {
32- return `${ hours - 12 } :${ time . slice ( 3 ) } pm` ;
31+ const minutes = time . slice ( - 2 )
32+ console . log ( hours )
33+
34+ if ( hours === 0 ) {
35+ return `12:${ minutes } am`
36+ }
37+ else if ( hours === 12 ) {
38+ return `12:${ minutes } pm`
39+ }
40+ else if ( hours > 12 ) {
41+ let newhours = hours - 12
42+ if ( newhours < 10 ) {
43+ return `${ String ( newhours ) . padStart ( 2 , "0" ) } :${ minutes } pm`
44+ }
45+ else {
46+ return `${ hours - 12 } :${ minutes } pm` ;
47+ }
3348 }
34- return `${ time } :${ time . slice ( 3 ) } am` ;
49+ else if ( hours < 10 ) {
50+ return `${ String ( hours ) . padStart ( 2 , "0" ) } :${ minutes } am`
51+ }
52+ else {
53+ return `${ hours } :${ minutes } am` ;
54+ }
55+
3556}
3657
3758const cases = [
You can’t perform that action at this time.
0 commit comments