Skip to content

Commit 23888b9

Browse files
committed
function bmi calculator written
1 parent bc05c26 commit 23888b9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// Below are the steps for how BMI is calculated
2-
32
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
4-
53
// 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-
74
// squaring your height: 1.73 x 1.73 = 2.99
85
// dividing 70 by 2.99 = 23.41
96
// Your result will be displayed to 1 decimal place, for example 23.4.
10-
117
// You will need to implement a function that calculates the BMI of someone based off their weight and height
12-
138
// Given someone's weight in kg and height in metres
149
// Then when we call this function with the weight and height
1510
// It should return their Body Mass Index to 1 decimal place
1611

1712
function calculateBMI(weight, height) {
18-
// return the BMI of someone based off their weight and height
19-
}
13+
var bmi = (weight / (height * height));
14+
return bmi.toFixed(1);
15+
}
16+
console.log(calculateBMI(70, 1.73));
17+
console.log(calculateBMI(95, 1.82));
18+
console.log(calculateBMI(52, 1.6));
19+
console.log(calculateBMI(110, 1.75));
20+
console.log(calculateBMI(65, 1.9));

0 commit comments

Comments
 (0)