Can someone tell me where I made a mistake?

Tell us what’s happening:

Your code so far


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


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.135 Safari/537.36.

Challenge: Replace Loops using Recursion

Link to the challenge:

You are putting code bellow this line

// Only change code above this line
which is the return function since its not outside it’s scope it gives an error

I think you are trying to return the product of the elements of an array.
but if you execute above code you will get sum of elements of that array.
remove the last “return product” statement which is not initialised and outside the function
mistakes I found:

  1. you are using + instead of * .
  2. In the base condition you are returning 0 , so you will get 0 as the answer .