Iterate Through an Array along with a For Loop

Tell us what’s happening:

The code appears to work, as long as the input array isn’t too long, and has only numeric values.

I’m also pretty sure the for loop is being used.

Your code so far

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line

function sum(arr) {
  function isum(arr, index) {
    for (; index < arr.length;) {
      return arr[index] + isum(arr, index + 1);
    }
    return 0;
  }
  return isum(arr, 0);
}

var total = 0;
total = sum(myArr);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop/

you really just need a for loop, like the example, you don’t need to create a function

the way you are using the for loop… wouldn’t an if statement be more appropriate?

You’re right.

Okay, so I’m marking this as a spoiler because it actually passes all the tests! Thanks for your help, @ieahleen!

var total = 0;
for (var index = []; index < myArr.length; index) {
  index += myArr[total = index + total];
}
total = Number(total);

Sorry for wasting your time.

I’m just messing around.

you really do not like using the for loop as it works, do you?
why do you need to do this complicated thing of having the loop variable as an array?