generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathbmi.js
26 lines (18 loc) · 962 Bytes
/
bmi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Below are the steps to calculate BMI for an adult
// The BMI calculation divides an adult's weight in kilograms (kg) by their height in metres (m) squared.
// 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:
// squaring your height: 1.73 x 1.73 = 2.99
// dividing 70 by 2.99 = 23.41
// Your result will be displayed to 1 decimal place, for example 23.4.
// Implement a function that calculates the BMI of someone using their weight and height
// Given someone's weight in kg and height in metres
// When we call this function with the weight and height
// Then it returns their Body Mass Index to 1 decimal place
function calculateBMI(weight, height) {
const BMI = weight / (height * height);
return BMI.toFixed(1);
}
const weight = 70; //weight in Kg
const height = 1.73; // height in m
const BMIResult = calculateBMI(weight, height);
console.log("BMI:", BMIResult);