🪆 Recursion · Mission 5 of 5
🐚 Fibonacci
0, 1, 1, 2, 3, 5, 8, 13… each number is the two before it added up. A function that calls itself twice can find any of them.
Your mission
- Make a Function fib, given n. If n <= 1, Return n.
- Otherwise Call fib(n - 1) into a, Call fib(n - 2) into b, and Return a + b.
- Main: Ask for n, Call fib(n) into answer, and Tell "fib(" + n + ") = " + answer. Step through a small one and watch the stack.
Getting the mission ready…