File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +24
-1
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- }
19+ }
20+
21+ // Predict and explain first...
22+ // =============> write your prediction here
23+ // I predict that the code will output 'undefined' because the function calculateBMI
24+ // does not return any value yet.
25+
26+ // =============> write your explanation here
27+ // The function calculateBMI currently has no return statement, so it will return 'undefined'.
28+ // To fix this, we need to perform the BMI calculation:
29+ // BMI = weight / (height * height)
30+ // Then, we round the result to one decimal place using toFixed(1).
31+
32+ // Finally, correct the code to fix the problem
33+ // =============> write your new code here
34+
35+ function calculateBMI ( weight , height ) {
36+ const bmi = weight / ( height * height ) ;
37+ return bmi . toFixed ( 1 ) ;
38+ }
39+
40+ // Example:
41+ console . log ( `The BMI of someone who weighs 70kg and is 1.73m tall is ${ calculateBMI ( 70 , 1.73 ) } ` ) ;
42+ // Output: The BMI of someone who weighs 70kg and is 1.73m tall is 23.4
You can’t perform that action at this time.
0 commit comments