# Im a beginner, please explain to me how to do this

**URL:** <https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 9, 2021, 3:45am UTC](https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144 "2021-09-09T03:45:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristianjacoberon](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/cristianjacoberon/32/231862_2.png) [@cristianjacoberon](https://forum.freecodecamp.org/u/cristianjacoberon)\
**Post date:** [September 9, 2021, 3:45am UTC](https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144/1 "2021-09-09T03:45:42Z")

</div>

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

```
  **Your code so far**

```

```js

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

```

```
  **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38`

**Challenge:** Replace Loops using Recursion

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/replace-loops-using-recursion)**
>
> Learn to Code — For Free

---

<div class="post-metadata">

**Author:** ![nivethakrishnan72](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nivethakrishnan72/32/203080_2.png) [@nivethakrishnan72](https://forum.freecodecamp.org/u/nivethakrishnan72)\
**Post date:** [September 9, 2021, 5:51am UTC](https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144/2 "2021-09-09T05:51:43Z")

</div>

@cristianjacoberon ,

The code you have written is correct, but a small change.

You have to `return 0` when `n<=0` and not `1`.

Hope this helps

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [September 9, 2021, 7:13am UTC](https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144/3 "2021-09-09T07:13:18Z")

</div>

Hi @cristianjacoberon !

Welcome to the forum!

In addition to the issue brought up by @nivethakrishnan72 you also need to fix this part to pass the tests.

> [@cristianjacoberon](#):
>
> `arr[a - 1]`

The letter a is not one of the parameters but the letter n is.

Once you fix that issue then the test will pass.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [March 10, 2022, 7:13pm UTC](https://forum.freecodecamp.org/t/im-a-beginner-please-explain-to-me-how-to-do-this/477144/4 "2022-03-10T19:13:52Z")

</div>

Closed on March 10, 2022, 7:13pm UTC

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