File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 1515// It should return their Body Mass Index to 1 decimal place
1616
1717function calculateBMI ( weight , height ) {
18- return ( weight / height ** 2 ) . toFixed ( 1 ) ;
18+ const bmi = weight / height ** 2 ;
19+ return Number ( bmi . toFixed ( 1 ) ) ;
1920}
2021
2122console . log ( calculateBMI ( 70 , 1.73 ) ) ;
Original file line number Diff line number Diff line change 55function formatAs12HourClock ( time ) {
66 const hours = Number ( time . slice ( 0 , 2 ) ) ;
77 const minutes = time . slice ( 3 , 5 ) ;
8- if ( hours >= 12 ) {
8+
9+ if ( hours === 0 ) {
10+ return `12:${ minutes } am` ;
11+ }
12+
13+ if ( hours === 12 ) {
14+ return `${ hours } :${ minutes } pm` ;
15+ }
16+
17+ if ( hours > 12 ) {
918 return `${ hours !== 12 ? hours - 12 : hours } :${ minutes } pm` ;
1019 }
1120 return `${ time } am` ;
@@ -27,7 +36,7 @@ console.assert(
2736
2837// Midnight
2938const outMidnight = formatAs12HourClock ( "00:00" ) ;
30- const targetMidnight = "00 :00 am" ;
39+ const targetMidnight = "12 :00 am" ;
3140console . assert (
3241 outMidnight === targetMidnight ,
3342 `current output: ${ outMidnight } , target output: ${ targetMidnight } `
You can’t perform that action at this time.
0 commit comments