javascript-tutorialsmade

JavaScript program to print Fibonacci series

This is another interesting program which is very useful for school and college students. This program sometimes asked in Interviews for Fresher, so be prepare yourself for the future.

If you don’t know what is Fibonacci series, here is the small example,

0, 1, 1, 2, 3, 5, 8…

0,1 -> 0 +1 =1 ( 1 is the next number)
0,1,2 -> 1+1 = 2 (2 is the next number)
0,1,2 -> 1+2 = 3
0,1,2,3 -> 2+3 = 5

So basically Fibonacci series is finding the next number by adding the first two numbers

Here is the JavaScript function to find the Fibonacci series function:

The above program is self explanatory, read the comments in the script. This function accepts limit as a parameter,

fibonacciSeries(10) -> this will print 10 values of Fibonacci series

Here is the usage example of the above fibonacci function:

On click of the button, getFibonacci() function will be called, then fibonacciSeries(limit) will be called by getFibonacci() by sending the limit value from text box.
Here is the live Demo of JavaScript Fibonacci series:

demo

 

 

Related Posts

Leave a Reply