File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 1414// Then when we call this function with the weight and height
1515// It should return their Body Mass Index to 1 decimal place
1616
17- function calculateBMI ( weight , height ) {
18- // return the BMI of someone based off their weight and height
17+ // I have made a small change to the test cases to ensure they match the expected output to 1 decimal place
18+ function calculateBMI ( weight , height ) {
19+ // Calculate BMI using the formula: weight (kg) / (height (m) * height (m))
20+ const bmi = weight / ( height * height ) ;
21+
22+ // Round to 1 decimal place and return
23+ return bmi . toFixed ( 1 ) ;
1924}
20- ( calculateBMI ( weight / hight * hight ) ) ;
21- let bmi = 85 / ( 1.54 * 1.54 ) ;
22- console . log ( bmi )
23- //here the result was 35.833307439446366 I need to round it to 1 decimal place
24- console . log ( bmi . toFixed ( 1 ) ) ;
25- //now the output is 35.8
26-
25+
26+ // Test cases
27+ console . log ( calculateBMI ( 85 , 1.54 ) ) ; // 35.8
28+ console . log ( calculateBMI ( 60 , 1.65 ) ) ; // 22.0
29+ console . log ( calculateBMI ( 72 , 1.80 ) ) ; // 22.2
30+ // now the function is reusable and correct.
You can’t perform that action at this time.
0 commit comments