0

Goal: write a loop that appends the sum of the last two items in [fib] to the end of [fib] for 20 loops and find the values of the last iteration.

Code Thus Far

let fib = [0,1]

let accumulator = 0

for (t=0;t<20;t++){
  endingDigits = fib[-1]+ fib[-2];
  accumulator =+ Number(accumulator) + Number(endingDigits);
  fib.push(endingDigits);
  t++;
}
console.log(fib)

Results I keep getting NaN - Which is why Rap the two negative indices in the number method.

Thanks for the help!

  • `=+` that looks like a typo already. You also have a `t++` at the end, even though the loop already increments `t`. – ASDFGerte Dec 11 '21 at 20:10
  • `fib[-1]` will in this case always be `undefined`. The `-1` index does **not** mean "one index from the end of the array". – Pointy Dec 11 '21 at 20:12

0 Answers0