Challenge: Printing Fibonacci Sequence
Task
Swipe to start coding
The Fibonacci sequence is a series of numbers where each term is the sum of the previous two. The sequence starts with:
0, 1, 1, 2, 3, 5, 8, 13, ...
Your task is to generate the first n Fibonacci numbers.
Instructions:
- Initialize:
let a = 0; let b = 1; let numTerms = 10; - Use a
whileloop to generate the sequence. - In every iteration:
- Add the current value of
ato an array. - Create a variable
nextTerm = a + b. - Update
a = b. - Update
b = nextTerm. - Decrement
numTerms.
- Add the current value of
- Return the full Fibonacci sequence as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 6. ChapterΒ 4
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.35
Challenge: Printing Fibonacci Sequence
Swipe to show menu
Task
Swipe to start coding
The Fibonacci sequence is a series of numbers where each term is the sum of the previous two. The sequence starts with:
0, 1, 1, 2, 3, 5, 8, 13, ...
Your task is to generate the first n Fibonacci numbers.
Instructions:
- Initialize:
let a = 0; let b = 1; let numTerms = 10; - Use a
whileloop to generate the sequence. - In every iteration:
- Add the current value of
ato an array. - Create a variable
nextTerm = a + b. - Update
a = b. - Update
b = nextTerm. - Decrement
numTerms.
- Add the current value of
- Return the full Fibonacci sequence as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 6. ChapterΒ 4
single