Hi let me start by saying this is an examination question so am not after any answers just guidance.
I am having trouble with the following program. When I try to run it javascript fails to perform the calculation. Any ideas what I am doing wrong would be appreciated.
[code]
<HTML>
<HEAD>
<TITLE>
Plant Experiments
</TITLE>
<SCRIPT LANGUAGE = “JavaScript”>
/*
* M150 TMA03 2009J Q3.
* Program to calculate average height of plants..
*
* 20/05/2009
*/
//Experimental results of Table 1 stored in arrays.
var plantHeights = [15,16,17,18,19];
var plantNumbers = [2,1,6,4,2];
var totalProducts = 0
var totalPlants = 0
//Part (ii).
//Write code to declare and initialise new array to represent the third row of the table.
var product = new Array (5);
//Part (iv).
//Write code to calculate the average height of the plants and write it out in the browser window.
for (var plant = 0; plant < plantNumbers.lengh; plant = plant + 1);
{
product[plant] = plantNumbers[plant] * plantHeights[plant];
}
for (var plant = 0; plant < plantNumbers.length; plant = plant + 1);
{
totalProducts = totalProducts + product[plant];
}
for (var plant = 0; plant < plantNumbers.length; plant = plant + 1);
{
totalPlants = totalPlants + plantNumbers[plant];
}
document.write (‘The average height of the plants in this experiement was ‘ + totalProducts / totalPlants + ‘cm’);
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>