JavaScript 1 Write code that computes the sum of the values
JavaScript
1.) Write code that computes the sum of the values stored in an integer array named myArray (you can assume that the array exists and already has values in it).
2.) Write code that computes the average of the values stored in an integer array named myArray (you can assume that the array exists and already has values in it)
Solution
Question 1:
var sum = 0;
for(var i=0; i<myArray.length; i++){
sum = sum + myArray[i];
}
document.write(\"The sum is \"+sum);
Question 2:
var sum = 0;
for(var i=0; i<myArray.length; i++){
sum = sum + myArray[i];
}
var average = sum/parseFloat(myArray.length);
document.write(\"The average is \"+average );
