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- const minutes = time . slice ( - 2 )
31+ const minutes = time . slice ( - 2 ) ;
32+ let hours12 ;
33+ let timePeriod ;
3234
3335 if ( hours === 0 ) {
34- return `12:${ minutes } am`
36+ hours12 = "12" ;
37+ timePeriod = "am" ;
3538 }
3639 else if ( hours === 12 ) {
37- return `12:${ minutes } pm`
40+ hours12 = "12" ;
41+ timePeriod = "pm" ;
3842 }
39- else if ( hours > 12 ) {
40- let newhours = hours - 12
41- if ( newhours < 10 ) {
42- return `${ String ( newhours ) . padStart ( 2 , "0" ) } :${ minutes } pm`
43- }
44- else {
45- return `${ hours - 12 } :${ minutes } pm` ;
46- }
47- }
48- else if ( hours < 10 ) {
49- return `${ String ( hours ) . padStart ( 2 , "0" ) } :${ minutes } am`
43+ else if ( hours < 12 ) {
44+ timePeriod = "am" ;
45+ hours12 = String ( hours ) . padStart ( 2 , "0" ) ;
5046 }
51- else {
52- return `${ hours } :${ minutes } am` ;
47+ else if ( hours > 12 ) {
48+ hours12 = String ( hours - 12 ) . padStart ( 2 , "0" ) ;
49+ timePeriod = "pm" ;
5350 }
54-
51+ return ` ${ hours12 } : ${ minutes } ${ timePeriod } `
5552}
5653
5754const cases = [
You can’t perform that action at this time.
0 commit comments