Please help me to solve this problem

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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

// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36

Challenge: Replace Loops using Recursion

Link to the challenge:

Do you have a question??

yes please help me sir

  1. Learn how to ask questions well. This is an important part of being a dev. Often, at work when I have to figure out how to ask a question, the process of figuring out how to articulate it will give me a deeper understanding of the problem, and sometimes will help me figure it out.
  2. Recursion is a difficult subject. There are many, many threads on here about it and about this problem specifically.
  3. Your code is almost there. I just needed to change one small thing. Learn how to debug. Debugging is about being a detective. Gather data. Put a console.log(n) at the beginning of the function. What is happening to n? What would we expect to happen?
1 Like

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