RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1377 | Replies: 6
Join Date: Apr 2006
Location: Sydney, Australia
Posts: 6
Reputation: viet_mafia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
viet_mafia viet_mafia is offline Offline
Newbie Poster

Javascript help!

  #1  
Mar 20th, 2007
Hi everyone, I'm pretty new to Javascript and I guess I'm pretty nooby at it so I have a problem with some Javascript I'm trying to write. Basically I'm creating some Javascript that will allow me to calculate someone's Body Mass Index (BMI) and so far with my code have absolutely no idea what's wrong with it. If you guys could lead me in the right direction it would be much appreciated :cheesy:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

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

<head><title>BMI Calculator</title>

 <script type="javascript">
 <!-- Hide script from non-script-friendly browsers
  function BMI Calculator(bmi)
  {
    var bmi = w / (h*h);
    return bmi;
  }
 //stop hiding the script-->
 </script>
</head>

<body>
<script type="javascript">
    <!-- Hide script from non-script-friendly browsers
    var n;
    var a;
    var h;
    var w;
    var bmi;
    n = prompt("What is your age? ","");
    if (n <= 17)
    {
    document.write("We are unable to calculate your BMI");
    }
    else if(age => 18)
    {
    h = prompt("What is your height in metres?","");
    w = prompt("What is your weight in kilograms?","");
    bmi = w / (h*h);

    if (bmi <= 19)
    { 
    message = "Underweight"; 
    }
    else if (bmi >= 20 && bmi <= 25)
    { 
    message = "Acceptable"; 
    }
    else if (bmi >= 26 && <=30)
    { 
    message = "Overweight"; 
    }
    else if (bmi >= 31)
    { 
    message = "Obese"; 
    }
    else
    { 
    message = "Error!"; 
    }

    content = ("<html><head><title>Your BMI</title></head><body><h1>BODY MASS INDEX (BMI) CALCULATOR</h1>
    <p>Your height= " + h + "<br>Your weight= " + w + <br>Your BMI= " + bmi + "</p>
    <p><h2>what your BMI Indicates</h2><br>" + message + ";

    document.write(content);
    }
    // stop hiding the script-->
</script>
</body>
</html>
AddThis Social Bookmark Button
Reply With Quote  

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:35 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC