# The user inputs his weight and his height, and the bot tells him his "IMC" value after some calculation, how do I do?

So, I am doing a fitness bot, and I asked the user´s target weight and also his height, and then I would like to let him know if he is doing right by aiming towards the target he inputed.

if a guy would like to weight 70kg and his height is 1,75m so, his IMC is 22,9 (IMC = 70 kg divided by the square of the height (1,75 x 1,75) = 22,9).

Like this he would be in a perfect shape. Below 18,6 he would be too slim, and above 25 he would be fat.And this is what I would like to calculate for him.

Is there a way to make this happen with database values?

1 Like

return new Promise(resolve => {
let height = data.variables.vHeight;
let squareheight = Math.pow (height , 2);
let weight = data.variable.vDesired_weight;
let imc = Math.pow (weight / squareheight);
let stringMedia = imc.toString();
resolve(stringMedia);
});

1 Like
``````let weight = data.variable.vDesired_weight;
``````

should be

``````data.variables
``````

s is missing

1 Like

to add onto Subhrahjit’s comment, I recommend logging the height and weight to see if the value being passed from the bot is valid.

you guys are awesome! thanks a lot! but I haven´t tryed yet… if the way I wrote is right (only the s missing) and the variables are string (or should they be numeber type?), is it gonna work?

I will make it later, I am watching yellow´s partner training, but I know you gys are gonna sleep soon!

Saludos!

ok, first try I got NaN (I think because I wrote 1.84 instead of 1,84 in the height)

I am doing this now:

return new Promise(resolve => {
let height = data.variables.vAltura;
let stringMedia = imc.toString();
resolve(stringMedia);
});

awwww I am so sad guys, I am using this function but it show NaN as a result… what do I have to do?

thanks

return new Promise(resolve => {
let height = data.variables.vAltura;
let stringMedia = imc.toString();
resolve(stringMedia);
});

Are you storing the data that you resolve in the variables you are accessing inthe UI?

Hi, I am storing in the variables!

Thanks a lote for the attention!!! I got it!

This is what I did:

return new Promise(resolve => {
let height = data.variables.vHeight;
let weight = data.variables.vWeight;
let imc = (weight / (height * height)).toFixed(2);
resolve(imc);
});

Let´s keep going!!! Regards

3 Likes