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/