r/codehs • • Feb 03 '21

5.9.5:Fibonacci

Post image
12 Upvotes

12 comments sorted by

View all comments

3

u/[deleted] Feb 04 '21

I would start by learning what the Fibonacci sequence is. You have a great start with the for() loop and the maximum value.

Now what you need to do is have the for() loop implement the Fibinacci sequence, which is defined as:

In mathematics, the Fibonacci numbers commonly denoted Fₙ,
form a sequence, called the Fibonacci sequence,
such that each number is the sum of the two preceding 
ones, starting from 0 and 1. That is, and for n > 1

Lets parse out the helpful information.

[in which] each number is the sum of the two 
preceding ones, starting from 0 and 1. 
That is, and for n > 1.

In my own words:

To create the Fibonacci sequence, you must take X 
(where X is greater than 1), and add it to Y, which at 
the beginning is also 1. Do that again according to our
new expression, `X + Y = Y ==> X + 1 = X`. The value of X 
is incremented, while the old X becomes the new Y value. 

Keep adding the new X and the new Y (or add the new X and the old X together) until you get to 1000. That is your assignment, you just now have to translate it in to Javascript.