Complex javascript frustum of a cone calculator wont calculate -


this first time using javascript , i'm trying make calculator tells volume of conical frustum using formula v = (1/3) * π * h * (r12 + r22 + (r1 * r2)) here attempt out.value doesn't seem want update. in likelihood i've been staring @ long , missing simple can't seem see it, appreciated greatly.

<script type="text/javascript"> function updateoutput() { var form = document.getelementbyid("calc"); var out = form.elements["z"] var num1 = parseint(form.elements["h"].value); var num2 = parseint(form.elements["s"].value); var num3 = parseint(form.elements["r"].value); var num4 = parseint(form.elements["g"].value); var num5 = math.pow(num3,2); var num6 = math.pow(num4,2); out.value = (1/3)*3.1459*num1*[num5+num6+(num3*num4)]; } </script> </head>  <body> <form id="calc"> <input name="h" type="number" value="0" /> <input name="s" type="number" value="0" /> <input name="r" type="number" value="0" /> <input name="g" type="number" value="0" /> <input name="calculate" type="button" value="calculate" onclick="updateoutput()" /> <div class="equals"> = </div> <output name="z">0</output> </form> 

var num5 = math.pow(num3,2); var num6 = math.pow(num4,2); 

the function math.pow, not math.pow (capital m).

also, seems work right now, it's odd way of doing it:

(1/3)*3.1459*num1*[num5+num6+(num3*num4)]; 

square brackets ([]) not parentheses - make array. you're multiplying array. happens, numerical value of single-item array item, still wouldn't rely on this.

function updateoutput() {  var form = document.getelementbyid("calc");  var out = form.elements["z"]  var num1 = parseint(form.elements["h"].value);  var num2 = parseint(form.elements["s"].value);  var num3 = parseint(form.elements["r"].value);  var num4 = parseint(form.elements["g"].value);  var num5 = math.pow(num3,2);  var num6 = math.pow(num4,2);  out.value = (1/3)*3.1459*num1*(num5+num6+(num3*num4));  }
<form id="calc">  <input name="h" type="number" value="0" />  <input name="s" type="number" value="0" />  <input name="r" type="number" value="0" />  <input name="g" type="number" value="0" />  <input name="calculate" type="button" value="calculate" onclick="updateoutput()" />  <div class="equals"> = </div>  <output name="z">0</output>  </form>


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -