# How do I a BMI Calculator?

From the Asset Store
Body mass index (BMI) is a formula that uses weight and height to estimate body fat (both metric and imperial units incl
• Hello Guys,

i need a BMI Calculator for my App, but i don´t know how i can insert my Javascript Code in Construct 2. Before i have try to open the Code with the Browser Function, but then it open my iPhone Safari Browser.. and that i don´t will, i will that the Java run Fullscreen in the App. Can anyone help me, how i can insert the Code?

The Code:

``````<script type='text/javascript'> <!--
function berechnen() {
var bmi;
var weight = document.bmiform.gewicht.value;
var height = document.bmiform.groesse.value;
if (weight < 10 || weight > 200) { alert("Falsches Gewicht.nBitte Daten erneut eingeben"); return null; }
if (height < 50 || height > 250) { alert("Falsche Grösse.nBitte Daten erneut eingeben"); return null; }
bmi = Math.round(weight / (Math.pow((height/100),2)));
output = "Ihr BMI beträgt " + bmi + ".\n";
if (bmi < 18) output += "Sie haben starkes Untergewicht.";
if (bmi == 18) output += "Sie haben deutliches Untergewicht.";
if (bmi == 19) output += "Sie haben leichtes Untergewicht.";
if (bmi >= 20 && bmi <= 24) output += "Dies liegt im idealen Bereich.";
if (bmi >= 25 && bmi <= 29) output += "Sie haben leichtes bis mässiges Übergewicht.";
if (bmi >= 30 && bmi <= 39) output += "Sie haben deutliches Übergewicht.";
if (bmi >= 40) output += "Sie haben sehr starkes Übergewicht.";
}
//-->
</script>
<form name="bmiform">
<input type="text" name="groesse" />
Größe in cm<br />
<input type="text" name="gewicht" />
Gewicht in kg<br />
<input type="button" name="submit" value="berechnen" onclick="berechnen();">
<br />
</form>
<br />[/code:1ln1apxi]``````
• Heya, this is quite simple.

1. Enter 2 textboxes (one for the height and one for the mass). You shall name them as in your script: weight, height

2. set up a local or global variable (up to you, what you intent to do) which will record the result.

3. in the event sheet you can then set the value of the variable to: Math.round(weight / (Math.pow((height/100),2)))

4. add an event to check the result and output what you want to a text object

EDIT: Okay, for step 3, you have to change the math a bit. Attached is an example

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Wow, thank you very much. Your Example is perfect.

• 3 posts