Sun Jun 21, 2009 6:04 am
Hi everyone, I'm a mature age TAFE student in Australia and I'm learning JavaScript as part of a Interactive Digital Media $ course and I'm having trouble getting a BMI script working. I've got the calculations working but the If and If Else statements aren't working. Can someone check it out for me please as I've got a test 2moro and really need this to work.
I know it should be easy, I can't see my mistake, any help would be greatly appreciated.
thanks michael
here's my code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<script type="text/javascript" language="javascript1.5">
//declare variables
var height
var weight
var numHeight
var numWeight
var bmi
//get user to enter height
height = window.prompt("Enter your height in centimetres ","");
//convert to number
numHeight = parseInt(height);
//get user to enter their weight
weight = window.prompt("Enter your weight in Kilograms ","");
//convert to number
numWeight = parseInt(weight);
//convert to metres
height = height/100;
//calculate bmi
bmi = weight/(height * height);
//round down bmi
bmiRounded = Math.round(bmi)
//display height, weight and bmi
{
document.writeln("Your entered height is ", + numHeight + " centimetres");
}
{
document.write("<br/>Your entered weight is ", + numWeight + " metres");
}
{
document.writeln("<br/>Your Body Mass Index is ", + bmiRounded + "");
}
//determine weight classification
if else(bmi<50)
{
document.writeln("You are<strong>Underweight</strong> eat more!");
{
if else(bmi>=30)
}
document.writeln("You are<strong>Obese</strong> see a doctor!");
}
if else(bmi>=25)
{
document.writeln("You are<strong>Overweight</strong> exercise more!");
}
if else(bmi>=18.5)
{
document.writeln("Your weight is <strong>Normal</strong> Congratulations!");
{
//display weight classification
document.writeln("<br/>Your BMI places you in the " + clss + "classification");
if else((numWeight<50) || (numHeight>2.2))
{
document.writeln("<br/>Your weight is less than 50 or your height is more tha 2.2metres.<br/>This result may be innacurate.");
}
do
{
height = window.prompt("","");
numWeight = parseInt(height);
while((numHeight) || isNaN(numHeight) || (numHeight>0));
}
</script>
</html>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.