Basic JavaScript - Replace Loops using Recursion

Tell us what’s happening:
Describe your issue in detail here.
please i need help to understand how this recursion works

  **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 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.75

Challenge: Basic JavaScript - Replace Loops using Recursion

Link to the challenge:

can you try first to tell us what you understand?

I understand recursion is a concept whereby a code calls itself … but i honestly don 't understand how it works

try the Watch a Video button, it has a good explanation

okay i will , thanks alot

Hi,

Do you struggle to comprehend the exercice that was asked ? Was my issue too, so if i can help you clarify as much as i can, it will be with a great pleasure

okay, thanks alot . Aesir, i just watched the video explanation i am going to try the challenge once more, if it don’t get it still i will let you know .

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
}
i got the answer but please can you explain to me what happened in the code

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