File tree Expand file tree Collapse file tree 1 file changed +22
-5
lines changed
Sprint-2/5-stretch-extend Expand file tree Collapse file tree 1 file changed +22
-5
lines changed Original file line number Diff line number Diff line change 22// Make sure to do the prep before you do the coursework
33// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.
44
5+ // function formatAs12HourClock(time) {
6+ // const hours = Number(time.slice(0, 2));
7+ // if (hours > 12) {
8+ // return `${hours - 12}:00 pm`;
9+ // }
10+ // return `${time} am`;
11+ // }
12+
513function formatAs12HourClock ( time ) {
6- const hours = Number ( time . slice ( 0 , 2 ) ) ;
7- if ( hours > 12 ) {
8- return `${ hours - 12 } :00 pm` ;
9- }
10- return `${ time } am` ;
14+ let hours = Number ( time . slice ( 0 , 2 ) ) ;
15+ let minutes = Number ( time . slice ( 3 , 5 ) ) ;
16+ let ampm = hours >= 12 ? 'pm' : 'am' ;
17+ hours = hours % 12 ;
18+ hours = hours ? hours : 12 ; // the hour '0' should be '12'
19+ minutes = minutes < 10 ? '0' + minutes : minutes ;
20+
21+ return `${ hours } :${ minutes } ${ ampm } `
1122}
1223
24+ console . log ( formatAs12HourClock ( "00:00" ) ) ;
25+ console . log ( formatAs12HourClock ( "23:59" ) ) ;
26+ console . log ( formatAs12HourClock ( "12:00" ) ) ;
27+ console . log ( formatAs12HourClock ( "21:20" ) ) ;
28+
29+
1330const currentOutput = formatAs12HourClock ( "08:00" ) ;
1431const targetOutput = "08:00 am" ;
1532console . assert (
You can’t perform that action at this time.
0 commit comments