<input type="button" value="Calculate Sum and Average" onclick="calculate(document)">
The sum is: <input type="text" name="sumBox" size="6"/><br/> The average is: <input type="text" name="averageBox" size="6"/><br/> </form> </body> </html>can someone help me debug this program??
<html>
<head><title>Final Exam Debug</title>
<script type="text/javascript">
function Calculate(f){
var sum, ctr;
for(ctr=0, ctr<=4, ctr++){
sum = elementsArray[ctr].value;
} //end of for loop
f.sumBox.value = sum;
f.averageBox.value = sum/4;
} //end of function
</script>
</head>
<body>
Please enter four numbers in the boxes below: <br/>
<form id="numbersForm" name="numbersForm">
<input type="text" name="num1Box" size="5"/><br/>
<input type="text" name="num2Box" size="5"/><br/>
<input type="text" name="num3Box" size="5"/><br/>
<input type="text" name="num4Box" size="5"/>
Your debugger has probably already told you that "elementsArray" is not defined. So, why don't you define it?
Is this a homework question? It says "Final Exam" at the top. Anyway, ToohrVyk is correct, it is probably worth defining elementsArray.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement