| Viewed 58 times

How to calculate the Fibonacci Number in javaScript?


I need to create a function that, given a number, returns the corresponding Fibonacci number

1 Answer
Mohammad Qandeel
Answered
16

The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, ...

 

function fibonacci(num) {
 if(num <= 1) return 1;
 return fibonacci(num - 1) + fibonacci(num - 2);
}
 


Related Questions