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.
- Initialize two variables:
prev(0) andcurr(1). - Use a loop to print exactly
countnumbers from the sequence, starting with 0. - In each step, calculate the
nextnumber, then updateprevandcurr.
01EXAMPLE 1
Input
count = 5Output
0
1
1
2
3Explanation: Prints the first 5 Fibonacci numbers.
Constraints
- Print each number on a new line.
- Use a single loop.
MathLoopsFundamentals
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
count5
Expected Output
0 1 1 2 3
Click RUN to test your solution