How do I a BMI Calculator?

Get help using Construct 2

Post » Tue Apr 01, 2014 5:25 am

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:

Code: Select all
<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.";
   alert(output);
}
//-->
</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 />
B
8
S
2
Posts: 53
Reputation: 687

Post » Tue Apr 01, 2014 7:53 am

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
You do not have the required permissions to view the files attached to this post.
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Tue Apr 01, 2014 11:14 am

Wow, thank you very much. Your Example is perfect.
B
8
S
2
Posts: 53
Reputation: 687


Return to How do I....?

Who is online

Users browsing this forum: eochranek, Unconnected and 17 guests