Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Others have given you the answer, some comments and suggestions, use what you want, ignore what you don't:</p> <ol> <li>Form controls must have a name to be successful (i.e. to be submitted with the form)</li> <li>XML-style markup is not required unless you are using XML or XHTML and sending documents as application/XML (extremely unlikely)</li> <li>The language attribute for script elements was deprecated in HTML 4, it is removed from HTML5</li> <li>By convention, variable names starting with a capital letter are reserved for constructors</li> <li>Where a mathematical operation other than "+" is applied to a string, it will be converted to a number, and unary "+" can be used instead of parseInt.</li> <li>Math.round can be used instead of toFixed(0)</li> <li>The factors for val2, val3 and result can be made dependent on the selected sex, removing the if..else statements.</li> <li>One option in a select element should be set as the default selected</li> </ol> <p>The code can be tidied and refactored to remove redundancy:</p> <pre><code>&lt;script type="text/javascript"&gt; function calculate() { var form = document.forms['f0']; var height = form.feet.value * 12 + +form.inches.value; var factor = form.gender.value == 'male'? [12.7, 6.8, 66] : [4.7, 4.7, 655]; var val1 = 6.23 * form.weight.value; var val2 = factor[0] * height; var val3 = factor[1] * form.age.value; var result = factor[2] + val1 + val2 - val3; dailyDeficit = form.goal.value * 3500 / 90; calMax = result * 1.55 - dailyDeficit; document.getElementById("answer").innerHTML = 'Your Daily Calorie Limit is: ' + calMax.toFixed(0); } &lt;/script&gt; &lt;form action="#" id="f0"&gt; Gender : &lt;select id="gender"&gt; &lt;option value="male"&gt;Male &lt;option value="female"&gt;Female &lt;/select&gt; &lt;br&gt; Weight : &lt;input type="text" id="weight"&gt;lbs. &lt;br&gt; Height : &lt;input type="text" id="feet"&gt;ft. &lt;input type="text" id="inches"&gt;in. &lt;br&gt; Age : &lt;input type="text" id="age"&gt; &lt;br&gt; Goal : &lt;select id="goal"&gt; &lt;option value="5"&gt;Lose 5 Pounds &lt;option value="10"&gt;Lose 10 Pounds &lt;option value="15"&gt;Lose 15 Pounds &lt;option value="20"&gt;Lose 20 Pounds &lt;option value="25"&gt;Lose 25 Pounds &lt;/select&gt; &lt;br&gt; &lt;input type="button" value="Give me my Daily Calorie Limit!" onclick="calculate()"&gt; &lt;/form&gt; &lt;div id="answer"&gt;&lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload