+ 1
Does anyone know how to calculate Body Mass Index (BMI)? Using "function" for 3 people.
Using "function", calculate 3 different BMI. => (84.5kg, 140kg, 83.9kg) => (1.8m, 1.93m, 1.65m) *with STATUS of according With BMI.
8 Respostas
+ 1
function(w1,h1,w2,h2,w3,h3)
{
var bmi1 = w1/(h1²);
var bmi2 = w2/(h2²);
var bmi3 = w3/(h3²);
if(bmi1<16) var bmi1 = "Severe Thinness";
else if (bmi1==16 || bmi1==17) bmi1 = "Moderate Thinness";
else if (bmi1>17 && bmi1<=18.5) bmi1 = "Mild Thinness";
else if (bmi1>18.5 && bmi1<=25) bmi1 = "Normal";
else if (bmi1>25 && bmi1<=30) bmi1 = "Overweight";
else if (bmi1>30 && bmi1<=35) bmi1 = "Obese Class 1";
else if (bmi1>35 && bmi1<=40) bmi1 = "Obese Class 2";
else if (bmi1>40) bmi1 = "Obese Class 3";
//...do the same for bmi2 and bmi3
return "BMIs: first: " + bmi1 + " second: " + bmi2 + " third: " + bmi3;
}
if you use two functions, it'd be better cause you would nt need to rewrite those if's for each variable.
+ 2
Hi Lucas, its code is good example. thank you for help!
+ 1
in which language?
+ 1
In JavaScript
+ 1
not completely sure you can just assign double values and then string right after, didnt test it. In case you can't, just create another variable to store the text part
+ 1
The code of Lucas, i will make using array to storage the parameters and run a for, no needing make more code... kk, sorry, i no speak inglish...
+ 1
LoooL vc fala português kkk
+ 1
Sim falo português.🙋