Skip to content

Commit d1cfea9

Browse files
committed
Implement BMI calculation in calculateBMI function and remove redundant comments
1 parent b23146f commit d1cfea9

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed
Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,20 @@
1-
// Below are the steps for how BMI is calculated
2-
3-
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
4-
5-
// For example, if you weigh 70kg (around 11 stone) and are 1.73m (around 5 feet 8 inches) tall, you work out your BMI by:
6-
7-
// squaring your height: 1.73 x 1.73 = 2.99
8-
// dividing 70 by 2.99 = 23.41
9-
// Your result will be displayed to 1 decimal place, for example 23.4.
10-
11-
// You will need to implement a function that calculates the BMI of someone based off their weight and height
12-
13-
// Given someone's weight in kg and height in metres
14-
// Then when we call this function with the weight and height
15-
// It should return their Body Mass Index to 1 decimal place
16-
17-
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
19-
}
20-
211
// Predict and explain first...
22-
// =============> write your prediction here
232
// I predict that the code will output 'undefined' because the function calculateBMI
243
// does not return any value yet.
254

26-
// =============> write your explanation here
275
// The function calculateBMI currently has no return statement, so it will return 'undefined'.
286
// To fix this, we need to perform the BMI calculation:
297
// BMI = weight / (height * height)
308
// Then, we round the result to one decimal place using toFixed(1).
319

3210
// Finally, correct the code to fix the problem
33-
// =============> write your new code here
34-
3511
function calculateBMI(weight, height) {
3612
const bmi = weight / (height * height);
3713
return bmi.toFixed(1);
3814
}
3915

16+
module.exports = calculateBMI;
17+
4018
// Example:
4119
console.log(`The BMI of someone who weighs 70kg and is 1.73m tall is ${calculateBMI(70, 1.73)}`);
4220
// Output: The BMI of someone who weighs 70kg and is 1.73m tall is 23.4

0 commit comments

Comments
 (0)