Forum Moderators: open
<HEAD>
<TITLE>
averages
</TITLE>
<SCRIPT LANGUAGE = "JavaScript">
//Experimental results of Table 1 stored in arrays.
var height = [15,16,17,18,19];
var number = [4,5,11,10,6];
//Write code to declare and initialise new array to represent the third row of the table.
var myarray = new Array(5)
var myarray = ["60","80","187","180","114"] ;
//Write code to calculate the average height and write it out in the browser window.
var values = [60, 80, 187, 180, 114];
var total = 0;
for ( var i = 0; i < values.length; ++i )
{
total += values[i];
}
var averageDivisor = 0;
for(var i = 0; i < number.length; i++)
averageDivisor += numbers[i];
var myarray = total / averageDivisor;
document.write("The average height " + values.join(",") + " is " + myarray);
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML> heights[0] with objects[0]... heights[1] with objects[1]... heights[2] with objects[2] etc... and at the end of the loop you'll have the running total. and then just divide that by the total value in the objects array -- which you can total up at the same time as you're going through the original loop. that way you only have one loop.