Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am creating a web-page that utilizes javascript for two functions. One

ID: 3540015 • Letter: H

Question

Hello, I am creating a web-page that utilizes javascript for two functions. One function calculates the users BMI and then alerts the message (I got the BMI Function working). However, my second function calorieIntake, isn't returning any alert message when I click the "Suggested Calorie Intake" button.


Here is a picture of the GUI that the code forms when implemented.

http://tinypic.com/view.php?pic=2hhegyf&s=5


And here is my code so far. Can you please just correct the function calorieIntake() so that it alerts the appropriate message when the if/else statement proves true. Whenever I click the "Suggested Calorie Intake" button now it doesn't alert any message...Please help!



<head>

<script language="JavaScript" type="text/JavaScript">


</script>


<script language="JavaScript" type="text/JavaScript">




function bmiCalc()

{

var height=document.getElementById('height box').value,

weight=document.getElementById('weight box').value;

weight/=2.2;

height/=39.37;

BMI=Math.round(weight/(height*height));

alert("BMI is:"+BMI);

}


</script>


<script language="JavaScript" type="text/JavaScript">




function calorieIntake()

{

var height=document.getElementById('height box').value,

weight=document.getElementById('weight box').value,

age=document.getElementById('age box').value,

gender=document.getElementByName('gender box');

calories=0;

var BMI=Math.round(weight/(height*height));


if(gender=="male"||gender="Male")

{

else if(23<BMI<25)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age));

alert("You are considered normal weight and should therefore consume:" +calories+" a day. "

+"This calorie intake will ensure that you remain the same weight");

}

else if(BMI<23)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age)+500);

alert("You are considered under-weight, and should therefore consume:" +calories+" a day. "

+"This calorie intake will cause you to gain one pound a week");

}

else if(BMI>25)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age)-500);

alert("You are considered over-weight and should therefore consume:" +calories+" a day. "

+"This calorie intake will cause you to lose one pound a week");

}

}

else(gender=="female"||gender=="Female")

{

else if(18.49<BMI<24.9)

{

calories=(655+(4.35*weight)+(4.7*height)-(4.7*age);

alert("You are considered normal weight and should therefore consume:" +calories+" a day. "

+"This calorie intake will ensure that you remain the same weight");

}

else if(BMI<18.49)

{

calories=(655+(4.35*weight)+(4.7*height)-(4.7*age)+500);

alert("You are considered under-weight, and should therefore consume:" +calories" a day. "

+"This calorie intake will cause you to gain one pound a week");

}

else if(BMI>24.9)

{

calories=(655+(4.35*weight)+(4.7*height)-(4.7*age)-500);

alert("You are considered over-weight and should therefore consume:" +calories+" a day. "

+"This calorie intake will cause you to lose one pound a week");

}

}

}


</script>

</script?

</head>

<html>

<BODY>


<p>Enter your height in inches:</p>

<input type="text" id="height box">


<p>Enter your weight in pounds<p>


<input type="text" id="weight box">


<p>Enter your age<p>

<input type="text" id="age box">


<p>Enter your gender<p>

<input type="text" id="gender box">


<p>

<input type="button" value="Your BMI:" id="button1">


<p>

<input type="button" value="Suggested Calorie Intake:" id="button2">


</form>


</body?

</html>

Explanation / Answer

<html>


<head>


<script type="text/javascript">



function bmiCalc()

{

var height=document.getElementById('height box').value,

weight=document.getElementById('weight box').value;

weight/=2.2;

height/=39.37;

BMI=Math.round(weight/(height*height));

alert("BMI is:"+BMI);

}


function calorieIntake()

{

var height=document.getElementById('height box').value,

weight=document.getElementById('weight box').value,

age=document.getElementById('age box').value,

gender=document.getElementById('gender box').value;

var calories=0;

weight/=2.2;

height/=39.37;

var BMI=Math.round(weight/(height*height));



if(gender=="male" || gender=="Male")

{




if(23<BMI && BMI<25)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age));



alert("You are considered normal weight and should therefore consume:" +calories+" a day. This calorie intake will ensure that you remain the same weight");

}


else if(BMI<23)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age)+500);

alert("You are considered under-weight, and should therefore consume:" +calories+" a day. This calorie intake will cause you to gain one pound a week");

}

else if(BMI>25)

{

calories=(66+(6.23*weight)+(12.7*height)-(6*age)-500);

alert("You are considered over-weight and should therefore consume:" +calories+" a day. This calorie intake will cause you to lose one pound a week");

}


}



else if(gender=="female" || gender=="Female")

{

if(18.49<BMI && BMI<24.9)

{

calories=655+(4.35*weight)+(4.7*height)-(4.7*age);

alert("You are considered normal weight and should therefore consume: "+calories+" a day. This calorie intake will ensure that you remain the same weight");

}

else if(BMI<18.49)

{

calories=(655+(4.35*weight)+(4.7*height)-(4.7*age)+500);

alert("You are considered under-weight, and should therefore consume:" +calories+" a day. This calorie intake will cause you to gain one pound a week");

}

else if(BMI>24.9)

{

calories=(655+(4.35*weight)+(4.7*height)-(4.7*age)-500);

alert("You are considered over-weight and should therefore consume:" +calories+" a day. This calorie intake will cause you to lose one pound a week");

}



}


}



</script>

</head>


<BODY>

<form>


Enter your height in inches:<br>

<input type="text" id="height box"></input><br>

Enter your weight in pounds<br>

<input type="text" id="weight box"></input><br>

Enter your age<br>

<input type="text" id="age box"></input><br>

Enter your gender<br>

<input type="text" id="gender box"></input><br>

<input type="button" value="Your BMI:" id="button1">

</input><br>

<input type="button" value="Suggested Calorie Intake:" id="button2">

</input>


</form>





</body>


</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote