How to create a BMI calculator.

Hi, I would like to create a Body Mass Index Calculator, but I don’t know how to link the user inputs and the calculator.

Thank you!

Do you mean like this? {REMOVED}

Yes, Exactly!!

Here you go

async function bmi() {
    let formula = ($w("#weight").value / $w("#height").value);
    let bmi = parseFloat((Number(formula) / $w("#height").value) * 10000).toFixed(1);
    $w("#bmi").value = await String(bmi);
    generateText(bmi);
}

function generateText(bmi) {
 if (Number(bmi) <= 18.5) {
        $w("#bmiText").text = 'You are underweight!';
    } else if (Number(bmi) > 18.5 && Number(bmi) <= 24.9) {
        $w("#bmiText").text = 'You BMI is normal.';
    } else if (Number(bmi) >= 25 && Number(bmi) <= 29.9) {
        $w("#bmiText").text = 'You are overweight!';
    } else if (Number(bmi) > 29.9) {
        $w("#bmiText").text = 'Warning, You are obese!';
    }
}

I hope you can take it from here.

Good luck.

1 Like

Thank you very much!!

Hi Shan,

Could you also guide how can I add this to one of my blog’s page?

i dont understand

link is not working. are weight, hight and bmi button names?

I thonk weight and height are input fieldsw the user can add their weight and heigth and the formul does the rest and puts the result in bmiText