Fibonacci

Write a program that prints the first 50 numbers of the Fibonacci sequence starting at 0.

  • The Fibonacci series is made up of a sequence of numbers in which the next one is always the sum of the previous two.
  • 0, 1, 1, 2, 3, 5, 8, 13…
solution.js
1function printFibonacci(n) {
2 const fib = [0, 1];
3
4 for (let i = 2; i < n; i++) {
5 fib[i] = fib[i - 1] + fib[i - 2];
6 }
7
8 return fib;
9}
10
11const fibonacci50 = printFibonacci(50);
12console.log(fibonacci50)