1// declare the array starting with the first 2 values of the fibonacci sequence
2 let fibonacci = [0,1];
3
4 function listFibonacci(num) {
5 // starting at array index 1, and push current index + previous index to the array
6 for (let i = 1; i < num; i++) {
7 fibonacci.push(fibonacci[i] + fibonacci[i - 1]);
8 }
9 console.log(fibonacci);
10 }
11
12 listFibonacci(10);
13
1function Fibonacci(num){
2 var before = 0;
3 var actual = 1;
4 var next = 1;
5
6 for(let i = 0; i < num; i++){
7 console.log(next)
8 before = actual + next;
9 actual = next
10 next = before
11 }
12}
13
14Fibonacci(100);
1// number fibonnaci to array format
2function fibonacci(nums) {
3
4 let fib = [0, 1];
5 let data = [];
6
7 for(let i = 2; i <= nums; i++) {
8 fib[i] = fib[i - 1] + fib[i - 2];
9 data.push(fib[i]);
10 }
11
12 return data;
13}
1function Fibonacci(valor){
2 var anterior = 0;
3 var atual = 1;
4 var proximo = 1;
5
6 for(let i = 0; i < valor; i++){
7 console.log(proximo)
8 anterior = atual + proximo;
9 atual = proximo
10 proximo = anterior
11 }
12}
13
14Fibonacci(100);
1var i;
2 var fib = []; // Initialize array!
3
4 fib[0] = 0;
5 fib[1] = 1;
6 for (i = 2; i <= 10; i++) {
7 // Next fibonacci number = previous + one before previous
8 // Translated to JavaScript:
9 fib[i] = fib[i - 2] + fib[i - 1];
10 console.log(fib[i]);
11 }
1// program to generate fibonacci series up to a certain number
2
3// take input from the user
4const number = parseInt(prompt('Enter a positive number: '));
5let n1 = 0, n2 = 1, nextTerm;
6
7console.log('Fibonacci Series:');
8console.log(n1); // print 0
9console.log(n2); // print 1
10
11nextTerm = n1 + n2;
12
13while (nextTerm <= number) {
14
15 // print the next term
16 console.log(nextTerm);
17
18 n1 = n2;
19 n2 = nextTerm;
20 nextTerm = n1 + n2;
21}