Can't calculate the Fibonacci number, there is someone strong on this issue?
Is not so much to calculate how many you want to understand how it is calculated.
Task: Implement a function fib which Fibonacci numbers. A function argument is the ordinal number.
f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)
Example:
2 == fib(3) // if formula then there must be fib(3) = f(n-1) + f(n-2) = f(2) + f(1) = 2+1=3, how 2 got ???
5 == fib(5) // then what is 5 ???
55 == fib(10)
You need to learn the concept of recursion.
"2 as it turned out" - as f(2) = f(n-1) + f(n-2)
Only you have the error, fib(3) = 2 and not 3
Code codepen.io/anon/pen/ezOxMQ?editors=1111