axel22

11-08-2012, 03:52 AM

I am trying to create a body fat calculator but I am not sure if my equations are correct. I feel like im missing a variable? I am not too sure about my equation for javascript. Please explain why you did what you did.

<html>

<head>

<title> BodyFat Formula </title>

<script type="text/javascript">

function BodyFat(weight, waist){

var weight, waist, bodyfat, total bodyfat

if ((weight >=0) , (waist >=0) , (total bodyfat >=0))

weight = Math.round(weightBox x 1.082) + 94.42

waist = Math.round(waistBox x 4.15)

bodyfat = (weight - waist)

total bodyfat = Math.round(bodyfat x 100) / total bodyfat)

weight = parseInt(document.getElementById("weightBox").value;

waist = parseInt(document.getElementById("waistBox").value;

bodyfat = = parseInt(document.getElementById("bodyfatBox").value;

// Assumes: weightBox contains the person's weight in pounds

// Assumes: waistBox contains the person's waist measurement in inches

// converts the weight and the waist measurement into numeric values

// calculates the BodyFat using the following Body Fat Formula(For Men):

// Factor1: (Total body weight x 1.082) + 94.42

// Factor2: Waist measurement x 4.15

// Lean Body Mass: Factor1 - Factor2

// Body Fat Weight: Total body weight - Lean Body Mass

// Body Fat Percentage: Rounded( (Body Fat Weight x 100) / total bodyweight )

}

</script>

</head>

<body>

<h2>BodyFat Formula</h2>

<p>

Weight: <input type="text" id="weightBox" size=4 value=150> pounds <br>

Waist measurement: <input type="text" id="waistBox" size=4 value=32> inches<br>

BodyFat: <input type="text" id="bodyfatBox" size=4 value=0> percent

</p>

<input type="button" value="Calculate body fat" onclick="BodyFat();">

<hr>

<div id="outputDiv"></div>

</body>

</html>

<html>

<head>

<title> BodyFat Formula </title>

<script type="text/javascript">

function BodyFat(weight, waist){

var weight, waist, bodyfat, total bodyfat

if ((weight >=0) , (waist >=0) , (total bodyfat >=0))

weight = Math.round(weightBox x 1.082) + 94.42

waist = Math.round(waistBox x 4.15)

bodyfat = (weight - waist)

total bodyfat = Math.round(bodyfat x 100) / total bodyfat)

weight = parseInt(document.getElementById("weightBox").value;

waist = parseInt(document.getElementById("waistBox").value;

bodyfat = = parseInt(document.getElementById("bodyfatBox").value;

// Assumes: weightBox contains the person's weight in pounds

// Assumes: waistBox contains the person's waist measurement in inches

// converts the weight and the waist measurement into numeric values

// calculates the BodyFat using the following Body Fat Formula(For Men):

// Factor1: (Total body weight x 1.082) + 94.42

// Factor2: Waist measurement x 4.15

// Lean Body Mass: Factor1 - Factor2

// Body Fat Weight: Total body weight - Lean Body Mass

// Body Fat Percentage: Rounded( (Body Fat Weight x 100) / total bodyweight )

}

</script>

</head>

<body>

<h2>BodyFat Formula</h2>

<p>

Weight: <input type="text" id="weightBox" size=4 value=150> pounds <br>

Waist measurement: <input type="text" id="waistBox" size=4 value=32> inches<br>

BodyFat: <input type="text" id="bodyfatBox" size=4 value=0> percent

</p>

<input type="button" value="Calculate body fat" onclick="BodyFat();">

<hr>

<div id="outputDiv"></div>

</body>

</html>