-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBMI.js
46 lines (36 loc) · 1022 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
let height; //in meters
let weight; //in kg
var bodymassindex; // kg/m^2
const bmi_status = ["underweight", "normal weight", "overweight", "obese"];
let weightStatus;
function calc_bmi(height, weight) {
bodymassindex = weight / (height)**2;
var bmi = bodymassindex.toFixed(1);
//return bodymassindex;
console.log(bodymassindex);
console.log(`Your BMI is:\n${bmi}`);
}
//(1.8, 50);
function getBMIStatus(bodymassindex) {
if (bodymassindex < 0) {
return "Please enter a valid number";
}
else{
if (bodymassindex < 18.5) {
weightStatus = bmi_status[0];
console.log(`You are ${weightStatus}`);
}
else if (bodymassindex > 18.5 && bodymassindex <= 24.9) {
weightStatus = bmi_status[1];
console.log(`You are ${weightStatus}`);
}
else if (bodymassindex >= 25 && bodymassindex <= 29.9) {
weightStatus = bmi_status[2];
console.log(`You are ${weightStatus}`);
}
else if (bodymassindex > 30.0) {
weightStatus = bmi_status[3];
console.log(`You are ${weightStatus}`);
}
}
}