I'm new at coding and am trying to figure out why this doesn't work. the function works fine I'm assuming there is a fundamental flaw in the sumArray function that is not processing
// SET UP FUNCTIONS FOR LATER USE
// sumArray - takes all values within an array and adds them
var sumArray = function(x){
var sum = 0;
for(i=0;i<x.length;i++) {
sum += parseInt(x[i]);
};
return sum;
};
// create an array and use sumArray function inside of a loop.
// This works
var arrayTest = new Array(1,2,3,4,5,6,7,8,9,10);
document.write (sumArray(arrayTest);
// This crashes the browser
for(i=0;i<10;i++){
document.write("<br/>" + sumArray(arrayTest) + "<br/>");
};
Thanks in advance for any insight.
[1, 2, 3 ...]instead ofnew Array(1, 2, 3 ... )