Tell us what’s happening:
I’m trying to understand how the beginning of the return statement works in the example given for this lesson. I understand the second half is the array position being multiplied but is it being multiplied by the the two parameters of the multiply function?
To go into depth, if the I call the function multiply([1,2,3],3);
I read the return statement simplified as" return multiply([1,2,3], 2) * 3". what exactly is being multiplied by 3?
**Your code so far**
function multiply(arr, n) {
if (n <= 0) {
return 1;
} else {
return multiply(arr, n - 1) * arr[n - 1];
}
}
console.log(multiply([1,2,3],3));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Challenge: Basic JavaScript - Replace Loops using Recursion
Link to the challenge: