Is there a glitch on this problem?

Tell us what’s happening:

  **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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15.

Challenge: Replace Loops using Recursion

Link to the challenge:

Hi @hasanicodes ,

Your code has two functions named sum -one inside the other. Remove one of them and your code should run fine.

1 Like

Thanks a lot! it worked, really appreciate the help. Have a great weeked.

This sort of thing most often happens when copy-pasting guide post solutions into your code. Recursion is a good check point of your level of understanding for function calls, return values, and scope, so I’d make sure that you can do it without looking at the solution.

yeah that was the case, been having a difficult time coming upon the end of javascript. Perhaps I should take a break and study the material offline.

We’re always here if you have questions or if there are things we can clarify/explain.

I dont want to cheat myself out of learning my favorite topics so I guess I will take you up on that offer. Thanks a lot!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.