# Basic JavaScript - Replace Loops using Recursion

You said that yourself!

It should mean the same thing, no matter if you pass in 4, 5, or 69218409820948.

yes if i’m correct. that’s what it should mean.

You are correct.

The next question is, what would the formula for the sum of the first 5 elements be if you knew `sum(arr, 4)`? Like if `sum(arr, 4) = 35`, then `sum(arr, 5) = ...`

should be 35 + arr(n + 1)

I think you have a bit of a syntax mixup here. What is `arr(n + 1)`?

a count up. the current index or value to get the next

What is `n`? Why are you using `()`? Why are you adding `+ 1`?

Don’t be too fancy.

Fill in the blank: `sum(arr, 5) = 35 + ____`

What, in symbols or words, should go in that blank?

sum(arr, 5) = 35 + 5 = 40.

Why 5? What is 5? Where did you find 5?

assuming that 5 is the nth value ie the last value in the array.

Don’t assume a random value here - how do you get the nth value of `arr`?

the nth value = array.length - 1

Writing half complete syntax will only confuse you.

Two problems here

1. The `n`th value won’t always be `arr.length - 1`. You can put lots of different numbers into the `n`th spot in an array. The index and the value are different things.

2. Nobody said the array has only 5 items.

You are close but need to be precise.

How do you get the `n`th value of the array `arr` without assuming anything at all about `arr`.

the nth value = arr.length(n - 1)

Still no.

You should probably try some of this syntax instead of guessing. Guessing and having me tell you ‘no’ will be very, very, very slow.

You could try researching:

You could also try your code and see if it works at all:

``````const arr = [5, 7, 8, 9, 1, 2, 4, 6, 9, 4, 5];
console.log(arr.length(n-1)); // does this work at all?
``````

n is not defined. i’m going to go back and restart the basic javascript from the top. i can see i missed a lot of details the first time round.