Fibonacci[i - 1] + fibonacci[i], i - 1 loop

There is this solution that reminds me of a question I had before. This is a function that creates an array of numbers that are Fibonacci numbers to a certain term supplied by the argument. I have tested substituting something with i - 1.

fibonacci.push(fibonacci[i] + fibonacci[i - 1])

This creates an error. It seems that i - 1 is inaccessible. I haven’t found answers to this. How does this not work?
“carrimaxx, post:1, topic:408743”

function sumFibs(num) {
  
  let fibonacci = [1,1]
  for(var i = 0; i <= num; i++){
    fibonacci.push(fibonacci[i] + fibonacci[fibonacci.length - 1]);
  }
  return fibonacci;
}

console.log(sumFibs(4));
  **Your browser information:**

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

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

Well, just looking at the the code, what is going to happen on first iteration. When i is 0, you will be doing:

fibonacci.push(fibonacci[0] + fibonacci[-1])`

What happens when you try to get the array element at an index of -1? What does that evaluate to? What happens when you add that to a number?

I think you need to reconsider how you’re indexing.

Thanks, I had only thought of numbers past 0 to plug in.