Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2012, 01:14 PM   PM User | #1
newbanks
New Coder

 
Join Date: Nov 2011
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
newbanks is an unknown quantity at this point
Appending javascript to weight/height to meters and kikograms

I have this working figuring BMI in lbs and Inches. I need to incorporate a prompt box asking S for Standard and M for Metric, IF S is selected then it will perform calculation as follows: bmi=weight * 703/ (height * height), If M is chosen then calculation will be: bmi=weight/(height * height) Here is what I have so far:

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtlm1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script type="text/javascript">

/*<![cdata[*/
//state the variable


var weight=prompt("Please enter your weight in lbs.");
var height=prompt("Please enter your height in inches");
var BMI = weight *703/(height * height);
weight = parseInt(weight);
height = parseInt(height);



if (BMI <18.5)
{
document.write("Your are Underweight for your Height and Weight");
}
else if (BMI <= 24.9)
{
document.write ("<p> You are of Normal Weight for your Height and Weight</p>");
}

else if (BMI <= 29.9)
{
document.write ("<p> You are overweight for your Height and Weight</p>");
}

else if (BMI >=30)
{
document.write ("<p> You are considered Obese for your Height and Weight</p>");
}



/*]]>*/

</script>
</head>
<body>
</body>
</html>
newbanks is offline   Reply With Quote
Old 02-07-2012, 01:26 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Take a look at http://javascript.about.com/library/blbmi1.htm - it uses a form inside the actual web page rather than a series of prompts to collect the information and also allows the selection you want between standard metric and american measures.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:56 AM.


Advertisement
Log in to turn off these ads.