File tree Expand file tree Collapse file tree 1 file changed +10
-16
lines changed
Sprint-2/3-mandatory-implement Expand file tree Collapse file tree 1 file changed +10
-16
lines changed Original file line number Diff line number Diff line change 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.
1+ function calculateBMI ( weight , height ) {
2+ // Square the height (height in meters)
3+ const heightSquared = height * height ;
104
11- // You will need to implement a function that calculates the BMI of someone based off their weight and height
5+ // Divide weight by height squared to get BMI
6+ const bmi = weight / heightSquared ;
127
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
8+ // Return the BMI rounded to 1 decimal place
9+ return bmi . toFixed ( 1 ) ; // toFixed returns a string, which is fine unless you need it as a number
10+ }
1611
17- function calculateBMI ( weight , height ) {
18- // return the BMI of someone based off their weight and height
19- }
12+ // Example usage:
13+ console . log ( calculateBMI ( 70 , 1.73 ) ) ; // Output: "23.4"
You can’t perform that action at this time.
0 commit comments