Home My space log
Language EN (English)

Fibonacci, fast

JavaScript Advanced astronaut ages teen+

The problem

The Fibonacci numbers go 0, 1, 1, 2, 3, 5, 8, 13 ... Each one is the sum of the two before it. Write a function fibonacci(n) that gives back the n-th one, counting from 0: fibonacci(0) is 0, fibonacci(1) is 1, fibonacci(7) is 13. It must also work fast for n = 50.

You will practice: loops, keeping state in variables, why repeating work is slow

Mode

Press Tab to indent. Press Esc and then Tab to move on to the next button.

Your code runs in your browser. We do not receive it or save it.

Test results

      What your code printed