Fibonacci sequence
As described on Wikipedia
In the Fibonacci sequence, each number is the sum of the previous two numbers. Fibonacci omitted the "0" and first "1" included today and began the sequence with 1, 2, 3, ... . He carried the calculation up to the thirteenth place, the value 233, though another manuscript carries it to the next place, the value 377. Fibonacci did not speak about the golden ratio as the limit of the ratio of consecutive numbers in this sequence.
Couple of ways to work with the Fibonacci sequence in Javascript
Get the Fibonacci number at position n:
console.log(nthFibonacciNumber(10)); // 55
Get the Fibonacci sequence up to n, using previous function:
printFibonacciSequence(10); // 1 1 2 3 5 8 13 21 34 55
Get the Fibonacci sequence up to n, using a for loop:
printFibonacciSequenceForLoop(10); // 1 1 2 3 5 8 13 21 34 55
Get the Fibonacci sequence up to n, using a while loop:
printFibonacciSequenceWhileLoop(10); // 1 1 2 3 5 8 13 21 34 55