function fibonacciSeries(number) {
let fibo = [0, 1]
for (var i = 2; i <= number; i++) {
fibo[i] = fibo[i - 1] + fibo[i - 2];
}
return fibo;
}
console.log(fibonacciSeries(10))
//Output: [ 0, 1, 1, 2, 3,5, 8, 13, 21, 34, 55]
<script>
//Fibonacci Series using Recursion
let n = 9;
// function returns the Fibonacci number
function fib(n) {
if (n <= 1)
return n;
return fib(n-1) + fib(n-2);
}
//function call
document.write(fib(n));
//This code is contributed by Surbhi Tyagi
</script>
// fibonacci series in javascript
const fibonacciSeries = (num) => {
let arr = [];
for(let i = 0; i <= num; i++) {
if(i == 0 || i == 1){
arr[i] = i;
}else{
arr[i] = arr[i - 1] + arr[i - 2];
}
}
return arr;
}
console.log(fibonacciSeries(6)) //[ 0, 1, 1, 2, 3, 5, 8];