Factorial can be used to find out how many ways to order a set of things. it looks like this 7!.
localStorage allows you to store and access strings in your browser.
The Fibonacci Sequence
is a series of numbers.
The sequence looks like this
0, 1, 1, 2, 3, 5, 8, 13, 21, 34…
To find the next number in the Fibonacci Sequence
you will have to find the sum of the two numbers before it.
To get the 4th number you will have to add 1 and 2 because 1 is the second number and 2 is the third number.
0, 1, 1, 2, 3
A way to implement the Fibonacci Sequence
is using a for loop that loops to the position you want to find.
JavaScript
function fibonacciSequence (position) {
// starting point
let array = [0, 1];
for (let i = 2; i <= position; i++){
// add the previous two value of the fibonacci sequence and push it into the array
array.push(arr[i - 2] + arr[i -1]);
}
// return the number in the array at the position passed into the function
return array[position];
}
The function takes in a number and returns the number in the Fibonacci Sequence in that position.
The function creates an array that holds the Fibonacci Sequence by repeatedly adding the last two numbers in the array.
It will repeat until the array includes the index of, position, which is passed to the function as an argument.
The position passed into the function is used to return a element from the array.
JavaScript
fibonacciSequence(4); // 3
This spiral can be made with the Fibonacci Sequence
.
Factorial can be used to find out how many ways to order a set of things. it looks like this 7!.
localStorage allows you to store and access strings in your browser.