Skip to content

Commit 3cfeecd

Browse files
committed
1-bmi.js committed
1 parent 5b73177 commit 3cfeecd

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@
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+
/**
18+
* Original function:
19+
* function calculateBMI(weight, height) {
20+
* return the BMI of someone based off their weight and height
21+
*}
22+
*/
23+
1724
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
19-
}
25+
// Calculate BMI: weight divided by height squared
26+
const bmi = weight / (height * height);
27+
28+
// Return the result rounded to 1 decimal place using the built-in Math library
29+
return Math.round(bmi * 10) / 10;
30+
}
31+
32+
// Test the function
33+
console.log(calculateBMI(70, 1.73)); // Should output: 23.4
34+
console.log(calculateBMI(80, 1.80)); // Test with another example and returns 24.7
35+

0 commit comments

Comments
 (0)