Tell us what’s happening:
Hello, I am trying to understand this recursion, but I am just not getting it. Even when I used the example the result was 6. I cannot seem to figure out why I am not getting 5 to pass this challenge. Thank you.
What I ended up doing was
return sum(arr, n-1) * (arr[n])-1;
}
but I am not sure if that is the correct way. I also show that I am only 98% when I submitted the challenge.
**Your code so far**
```js
function sum(arr, n) {
// Only change code below this line
if (n <= 0) {
return arr[0];
}
else {
return sum(arr, n - 1) * arr[n];
}
// 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/79.0.3945.88 Safari/537.36
.
Challenge: Replace Loops using Recursion
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion