# 6+ JavaScript Programs to Print Fibonacci Series

This post contains a total of 6+ JavaScript Program Examples with Source Code to Print Fibonacci Series. All these Fibonacci Series programs are made using JavaScript.

You can use the source code of these examples with credits to the original owner.

## JavaScript Programs to Print Fibonacci Series

### 1. By Gopinath M

Made by Gopinath M. A simple JavaScript Program To Display Fibonacci Series. Source

``````<!DOCTYPE html>
<html lang="en">
<style>
body {
background-color:bisque;
}
button {
color:#fff;
background-color:#337ab7;
border-color:#2e6da4;
}
input{
}
</style>
<body>
<h1>Program To Display Fibonacci Series</h1>
<form name="form">
<label>Enter Number</label>
<input type="text" name="field">
<button type="button" onclick="fibo()">Submit</button>
</form>
<script>
/* declare 4 variables */
var f1=0, f2=1, f3=0, n;

/* function definition */
function fibo() {

/* get the user entered value */
var n = parseInt(document.form.field.value);
/* print it to check */
console.log(n);

/* to print the first value which is 0 by default */
document.write("<h2>" + "0");

/* enters the loop */
do{
f1=f2;
f2=f3;
f3=f1 + f2;
document.write("<h2>" + f3);
}

/* repeat it till f3 lesser than n*/
while(f3 < n);
}

</script>
</body>
</html>
``````

### 2. By Brent Meeusen

Made by Brent Meeusen. Program to display the Fibonacci series numbers upto the number a user inputs in “var maxN = 25”. Source

`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`
``````<!DOCTYPE html>
<html>
<title>Fibonacci Sequence </title>
<body>
<p>The Fibonacci Sequence adds the last two numbers up, which creates the next number. The begin numbers are 1 and 1. </p>
<p id="seq"></p>
<script>
// Feel free to play with these numbers!
var n = [1, 1]; // Beginning numbers (don't increase the number of numbers!)
var maxN = 25; // The amount of numbers to be shown

// Don't change anything from here!
var p;
var i = n.length;

p = document.getElementById("seq");
p.innerHTML = n[0] + " - " + n[1] + " - ";
seq();
}

function seq() {
n[i] = n[i - 1] + n[i++ - 2];
p.innerHTML += n[i - 1] + " - ";
if(i <= maxN) {
seq();
}
}
</script>
</body>
</html>``````

### 3. By MOHD AYAZ ALAM

Made by Mohd ayaz alam. This JavaScript program uses the prompt to take input number and print the Fibonacci Series. Source

```0
1
1
2
3
5
8
13
21
34```
``````var value = prompt("Enter the value :");
var a = 0;
var b = 1;
for (var i = 0; i < value; i++) {
document.write(a);
document.write("<br>");
c = a + b;
a = b;
b = c;
}``````

### 4. By Rishabh

Made by Rishabh. You have to click the start button to start the program, after that you will need to enter the amount of Fibonacci numbers you want to print. Source

```0
1
1
2
3
```
``````<!DOCTYPE html>
<html>
<title></title>
<body>
<button onclick = create()>start</button>
<script>
function fibo(n){
var start = 0;
var end = 1;
var newno;
let result = "";
for(var i = 0; i < n ; i++){
result += start + "\n";

newno = start + end;
start = end;
end = newno;
}
}
function create(){
var input = prompt("Enter number for fibonacci series");
fibo(input);
}
</script>

</body>
</html>``````

### 5. By Vardhan C A

Made by Vardhan C A. Source

```enter the number of terms in fibonacci series
10
fibonacci series till terms 10

0
1
1
2
3
5
8
13
21
34```
``````<!DOCTYPE html>
<html>
<title>fibonacci seiries</title>
<body>
<script>
var a=0,b=1,c,i,n;
document.write("enter the number of terms in fibonacci series<br>");
var n=prompt(n);
document.write("fibonacci series till terms\n"+n+"<br>");
for(i=1;i<=n;i++)
{
document.write("<br>"+a);
c=a+b;
a=b;
b=c;
}
</script>
</body>
</html>``````

### 6. By Shekhar Kumar

Made by Shekhar Kumar. Simple JavaScript program that prints the Fibonacci series numbers upto 100 in the Console. Source

```0
1
2
3
5
8
13
21
34
55
89
```
``````const Fs = () => {
let x = 0;
let y = 1;
let fn = x+y; //0+1 = 1
console.log(x);

while (fn < 100) {
console.log(fn);
//swapping numbers
x = y;
y = fn;
fn = x + y;
}
}
Fs();``````

### 7. By Mohan Raman

```0
1
1
2
3
5
8
13
21```
``````<html>
<title>fibonacci series</title>
<script type="text/javascript">
var var1=0;
var var2=1;
var var3;
var num=window.prompt("enter the limit to generate fibonacci no");
document.write(var1+"<br/>");
document.write(var2+"<br/>");
for(var i=3;i<=num;i++)
{
var3=var1+var2;
var1=var2;
var2=var3;
document.write(var3+"<br/>");
}
</script>