Tell us what’s happening:
I have coded these and I am not sure how to make it to where the sum([1], 0)
should equal 0. and * sum([2, 3, 4, 5], 3)
should equal 9. passes. What am I missing that I need to put in or take out?
Your code so far
function sum(arr, n) {
// Only change code below this line
if (n<=0){
return 1;
} 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/16.1 Safari/605.1.15
Challenge: Basic JavaScript - Replace Loops using Recursion
Link to the challenge: