# How To Get Fibonacci Series In JavaScript Example

Hello Friends,

Now let's see example of how to get fibonacci series example. We will check how to get fibonacci series. This is a short guide on get fibonacci series in javascript. Let's get started with how to get fibonacci series in javascript.

Here i will give you many example how to get fibonacci series using javascript.

Example : 1
<html>
<title>How To Get Fibonacci Series In JavaScript Example - MyWebtuts.com</title>
<body>
<h3>How To Get Fibonacci Series In JavaScript Example - MyWebtuts.com</h3>
<script>
var a1 = 0,  a2 = 1, a_num, i;
var num = parseInt (prompt (" Enter the limit for Fibonacci Series :"));
document.write( "Fibonacci Series : ");

for ( i = 1; i <= num; i++)
{
document.write (" <br> " +  a1);
a_num = a1 + a2;
a1 = a2;
a2 = a_num;
}
</script>
</body>
</html>
Output :
Enter the limit for Fibonacci Series : 10
Fibonacci Series :
0
1
1
2
3
5
8
13
21
34
Example : 2
<html>
<title>How To Get Fibonacci Series In JavaScript Example - MyWebtuts.com</title>
<body>
<h3>How To Get Fibonacci Series In JavaScript Example - MyWebtuts.com</h3>
<script>
var number = 8;
var a1 = 0, a2 = 1;
var n_num = 0;

document.write( " Fibonacci series of the number 8 : " + "<br>")
for (i = 1; i < number; i++)
{
if ( i <= 1)
n_num = i;

else
{
n_num = a1 + a2;
a1 = a2;
a2 = n_num;
}
document.write( " Add " + a1 + " and " + n_num + " = " + (a1 + a2) + "<br>" );
}
</script>
</body>
</html>
Output :
Fibonacci series of the number 8 :
Add 0 and 1 = 1
Add 1 and 1 = 2
Add 1 and 2 = 3
Add 2 and 3 = 5
Add 3 and 5 = 8
Add 5 and 8 = 13
Add 8 and 13 = 21