Skip to content

Commit ab8b7e0

Browse files
committed
Implement BMI calculation in calculateBMI function and update predictions and explanations
1 parent 15ab890 commit ab8b7e0

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,27 @@
1616

1717
function 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

0 commit comments

Comments
 (0)