Hi,
Im trying to make a calculator that on click displays the sum of the data in the array and provides the mean/ average.
I have the formula for the mean = number of items(array.length?) * sum of array.
Please help
Can anyone recommend a superb/afordable/online javascript course?
<html>
<head>
<title>Aggregates</title>
<script type="text/javascript">
var array = new Array();
function insert(val)
{
array[array.length]=val;
}
function show()
{
var string="";
for(i = 0; i < array.length; i++)
document.getElementById("e").value = string =string+array[i]+"\n";
}
function sum(array)
{ numberTotal = 0
for (var total = 0; total < array.length; total = total + 1)
numberTotal = numberTotal + numberArray[total]
return numberTotal
document.getElementById("sum").value = numberTotal.value;
}
</script>
</head>
<body>
<h1>Aggregates</h1>
<h3>Add as many numbers as you like </br> to the list, then click Calculate.</h3>
<form id="form">
<input type="text" name="name" value="">
<input type="button" value="Add to list" onClick="insert(this.form.name.value),show();"></br>
<textarea name="txt" id="e" rows="10" ></textarea> </br>
<h4>Total (Sum)/h4>
<input type="text" id="Sum" value="0"></br>
<input type="button" value="Calculate" onClick="sum(array);"></input>
<h4>Average/h4>
<input type="text" id="answer" value="0"></br>
<input type="button" value="Reset" onClick="form.reset();" />
</form>
</body>
</html>![]()





/h4>
Reply With Quote





Bookmarks