Tell us what’s happening:
Can someone help me to understand what is going on in the else return statement to pass these two tests: sum([2, 3, 4], 1) should equal 2. sum([2, 3, 4, 5], 3) should equal 9.
I’m having a very hard time wrapping my head around this problem.

Your code so far

function sum(arr, n) {
// Only change code below this line
function sum(arr, n) {
if (n <= 0) {
return 0;
} else {
return sum(arr, n - 1) + arr[n-1];
}
}
// Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36.

Oops just realized I entered an extra ‘}’ to the end of the code but this is the solution that was provided for this problem… Maybe there’s an error and that’s why I’m so confused,?

hi there…guys where do you get this sum([2,3,4], 1)…the exemple doesnt exist on my page and I feel like I learn in blind mode…somehow I managed to guess the code and when I hit test, its starts to tell me :
sum([1], 0) should equal 0.
sum([2, 3, 4], 1) should equal 2…
from where???etc…I cant see anywhere on my page the example …!!!