Skip to content

Commit e29954a

Browse files
committed
Correct the BMI function and the necessary explanation
1 parent 6b17b68 commit e29954a

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
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+
/**
1718
function calculateBMI(weight, height) {
1819
// return the BMI of someone based off their weight and height
19-
}
20+
}
21+
*/
22+
23+
/**
24+
This function works by:
25+
26+
Squaring the height.
27+
28+
Dividing the weight by the squared height.
29+
30+
Using toFixed(1) to round the BMI to 1 decimal place and converting it back to a number.
31+
*/
32+
33+
// Function to calculate BMI
34+
function calculateBMI(weight, height) {
35+
// Calculate BMI: weight divided by height squared
36+
const bmi = weight / (height * height);
37+
38+
// Round the result to 1 decimal place and return
39+
return Number(bmi.toFixed(1));
40+
}
41+
42+
// Example usage:
43+
console.log(calculateBMI(70, 1.73)); // Output: 23.4
44+
console.log(calculateBMI(60, 1.6)); // Output: 23.4
45+
console.log(calculateBMI(90, 1.8)); // Output: 27.8
46+
47+

0 commit comments

Comments
 (0)