[Solved] confused generating fibonacci sequence


Follow the loops iterations one by one

in the third iteration,

fib[2] = fib[2-2] + fib[2-3]; is fib[2] = fib[0] + fib[-1];

fib[2] = 0 + undefined;

fib[2] = undefined;

in the fourth iteration,

fib[3] = fib[3-2] + fib[3-3]; is fib[3] = fib[1] + fib[0];

fib[3] = 1 + 0;

in the fifth iteration,

fib[4] = fib[4-2] + fib[4-3]; is fib[4] = fib[2] + fib[1];

fib[4] = undefined + 1;

fib[4] = NaN;

You can figure out the rest.

Btw you could use a debugger with breakpoints.

It would be really useful in this situation.

4

solved confused generating fibonacci sequence