Hey there! I'm a bit confused and couldn't find the solution anywhere. Are you able to take a look at my code and point out what's wrong with it? I promise, I'm not trying to get you to do my homework!
Question: Loop through an array For this challenge, write a function that accepts an array as input. The function should loop through each element of the array and return the sum of all values. Mastering the ability to iterate over arrays is crucial in coding so make sure to practice this often. Try to complete this task within 2 minutes before moving on to the next challenge. (Test cases: [0] should return 0, [1,2,5] should return 8, [-5,2,5,12]should return 14)
My code:
function iterArr(arr) {
//your code here
var s = new Array();
a[0]=0;
a[1]=[1+2+5];
a[2]=[-5+2+5+12];
for (var i =0;i<s.length;i++){
sum = sum +s;
}
return sum;
}