Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 15 of 15
Thread: Mosteller formula confusion

11092012, 04:58 AM #1
 Join Date
 Oct 2012
 Posts
 6
 Thanks
 2
 Thanked 0 Times in 0 Posts
Mosteller formula confusion
Im trying to figure out/understand about multiple RETURN functions. But, I cant execute my function.
Code:function SqFeetToSqMeters(sqFeet) { var sqMeters; sqMeters = sqFeet/10.764; return sqMeters; } function PoundsToKilograms(pounds) { var kg; kg = pounds/2.205; return kg; } // function CentimetersToInches(cm) { var inches; inches = cm / 2.54; return inches; } function HEIGHT(surface, weight) {var surface = 'sqMeter'; var weight = 'kg'; height = Math.pow(surface, 2) * 3600) / weight); return height; } function FINDHEIGHT() { var surface, weight, height; surface= parseFloat(document.getElementById('SBox').value); weight = parseFloat(document.getElementById('WBox').value); height= Math.round(HEIGHT(surface,weight)); document.getElementById('HBox').value = height; var str1='Your Height is '; document.getElementById('outputDiv').innerHTML= str1.concat(height); } </script> </head> <body> <h2>Using the Mosteller formula to calculate the height from the body Surface and Weight</h2> <p> surface: <input type="text" id="SBox" size=4 value=19.45> sq ft.<br> weight: <input type="text" id="WBox" size=4 value=150> pounds<br> height(calculated): <input type="text" id="HBox" size=4 value=0> inches<br> <input type="button" value="calculate the height" onclick="FINDHEIGHT();"> </p> <hr> <div id="outputDiv"></div> </body> </html> </html>
Last edited by axel22; 11092012 at 05:56 AM. Reason: added an OutputDive and added a math.pow for the height formula.
11092012, 05:25 AM
#2
What is the question here?
This part of your code makes no sense at all:
How can you multiply 'sqMeter' * 'sqMeter' and then divide by 'kg'???Code:var surface = ('sqMeter'); var weight = ('kg'); height = Math.round(surface * surface) * 3600) / weight);
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11092012, 05:27 AM
#3
If you think you were magically converting surface from square feet to square meters, you weren't
All you were doing was assigning the *STRING* 'sqMeter' to the variable.
Just incidentally wiping out the value of surface that was passed into the function.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11092012, 05:58 AM
#4
 Join Date
 Oct 2012
 Posts
 6
 Thanks
 2
 Thanked 0 Times in 0 Posts
the whole point is to find HEIGHT by the representing values of surface and height from being passed from (surface) sqFt to sqMeters and (weight) passed from lbs to kgs using the Height formula which will use the previous functions to calculate height into inches.
11092012, 07:15 AM
#5
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 18,079
 Thanks
 203
 Thanked 2,542 Times in 2,520 Posts
Last edited by Philip M; 11092012 at 07:19 AM.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
11092012, 07:19 AM
#6
Yes?
And you *HAVE* a function there that will convert square feet to square meters:
But you never use it.Code:function SqFeetToSqMeters(sqFeet) { var sqMeters; sqMeters = sqFeet/10.764; return sqMeters; }
Instead, you just change surface from a number into a string.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11092012, 07:24 AM
#7
Most of the code looks right.
It's just these two lines that are total hash:
What you want, instead isCode:var surface = 'sqMeter'; var weight = 'kg';You get to figure out what someConversionOf needs to be.Code:surface = someConversoinOf( surface ); weight = someConversionOf( weight );
Notice that I did *NOT* use var there. That *IS* important.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11092012, 07:55 AM
#8
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 18,079
 Thanks
 203
 Thanked 2,542 Times in 2,520 Posts
I now find that the Mostella formula calculates body surface area from height and weight for medication doses. But the OP's script seems to calculate the subject's height from his weight and body surface area. That can't be right.
The formula is
BSA (m²) = ( [Height(cm) x Weight(kg) ]/ 3600 )½ e.g. BSA = SQRT( (cm*kg)/3600 )
or in inches and pounds: BSA (m²) = ( [Height(in) x Weight(lbs) ]/ 3131 )½
Given that the data can be input as Metric or Imperial I don't see the point of converting the units.
Note. My doctor tells me that I am exactly the correct weight  for a man 2.4 metres tall.
Last edited by Philip M; 11092012 at 08:05 AM.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
11092012, 09:02 PM
#9
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11102012, 07:24 AM
#10
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 18,079
 Thanks
 203
 Thanked 2,542 Times in 2,520 Posts
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
11102012, 08:26 PM
#11
Huh...I thought I looked up your location with Google once upon a time and street view showed it to be a physicians office. Was over a year ago, so I don't remember the details or where I found the address. Likely was a bogus address and/or a shared office or some such?
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11102012, 09:00 PM
#12
 Join Date
 Jun 2002
 Location
 London, England
 Posts
 18,079
 Thanks
 203
 Thanked 2,542 Times in 2,520 Posts
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
11102012, 11:25 PM
#13
 Join Date
 Oct 2012
 Posts
 6
 Thanks
 2
 Thanked 0 Times in 0 Posts
is that Math.pow() function even being used correctly?
11112012, 10:19 PM
#14
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
11112012, 10:20 PM
#15
Philip: Yes! That's the one. Been so long ago I don't remember even where I got that from.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.