Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    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"

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

    <script type="text/javascript">

    //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>");



  2. #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    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.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts