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.
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:
you are using + instead of * .
In the base condition you are returning 0 , so you will get 0 as the answer .