function fib(num) { var arr = []; if (num == 1) { return arr = [1]; } else if (num == 2) { return arr = [1, 1]; } else { arr = [1, 1]; for (var i = 2; i < num; i++) { arr[i] = arr[i-1] + arr[i-2]; } return arr; } } console.log( fib(8));