The Fibonacci Sequence

EasyAcc. 94.1%
+20 XP 8

Nature's Pattern

The Fibonacci sequence starts with 0 and 1. Every number after that is simply the sum of the two numbers before it: 0, 1, 1, 2, 3, 5, 8, 13, 21...

The Assignment

Your function receives a parameter named count.

  1. Initialize two variables: prev (0) and curr (1).
  2. Use a loop to print exactly count numbers from the sequence, starting with 0.
  3. In each step, calculate the next number, then update prev and curr.

01EXAMPLE 1

Inputcount = 5
Output0 1 1 2 3

Explanation: Prints the first 5 Fibonacci numbers.

Constraints

  • Print each number on a new line.
  • Use a single loop.
MathLoopsFundamentals
JavaScript
Loading...
2 Hidden

Input Arguments

count5

Expected Output

0
1
1
2
3

Click RUN to test your solution