File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 1616
1717function calculateBMI ( weight , height ) {
1818 // return the BMI of someone based off their weight and height
19- return ( weight / ( height * height ) ) . toFixed ( 1 ) ;
19+
20+ return Number ( weight / ( height * height ) ) . toFixed ( 1 ) ;
2021}
Original file line number Diff line number Diff line change @@ -37,9 +37,20 @@ console.assert(
3737 `current output: ${ currentOutput7 } , target output: ${ targetOutput7 } `
3838) ;
3939
40+ function formatAs12HourClock ( time ) {
41+ const hours = Number ( time . slice ( 0 , 2 ) ) ;
42+ const minutes = time . slice ( 2 ) ; // ":MM"
43+
44+ if ( hours === 0 ) return `12${ minutes } am` ;
45+ if ( hours === 12 ) return `12${ minutes } pm` ;
46+ if ( hours > 12 ) return `${ String ( hours - 12 ) . padStart ( 2 , "0" ) } ${ minutes } pm` ;
47+
48+ return `${ time } am` ;
49+ }
50+
4051// I tested the function with edge cases around midnight and noon.
4152// I found that the original function handled times like "08:00" and "23:00",
42- // but it did not correctly handle "00:xx" (midnight times) or "12:xx" (noon times).
53+ // but it did not correctly handle "00:xx" (midnight times) or "12:xx" (noon times).
4354
4455// Bugs found:
4556// - "00:00" returned "00:00 am" instead of "12:00 am"
You can’t perform that action at this time.
0 commit comments