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 isFibonacci(n) {
2 var fib,
3 a = (5 * Math.pow(n, 2) + 4),
4 b = (5 * Math.pow(n, 2) - 4)
5
6 var result = Math.sqrt(a) % 1 == 0,
7 res = Math.sqrt(b) % 1 == 0;
8
9 //fixed this line
10 if (result || res == true) // checks the given input is fibonacci series
11 {
12 fib = Math.round(n * 1.618); // finds the next fibonacci series of given input
13 console.log("The next Fibonacci number is " + fib);
14
15 } else {
16 console.log(`The given number ${n} is not a fibonacci number`);
17 }
18}
19
20$('#fib').on("keyup change", function() {
21 isFibonacci(+this.value)
22})
1'use strict';
2
3let fibonacci: number[] = [0, 1];
4
5function listFibonacci(num: number) {
6 for (let i: number = 2; i < num; i++) {
7 fibonacci[i] = fibonacci[i - 2] + fibonacci[i - 1];
8 }
9 return fibonacci;
10}
11console.log(listFibonacci(10));
12