Fibonacci Series In JavaScript With Source Code

Fibonacci Series In JavaScript With Source Code

The Fibonacci Series In JavaScript is developed using JavaScriptCSSbootstrap, and HTML.

This Project With Source Code is a small and interesting project to generate the Fibonacci series of the required length.

The user has to enter the number for generating the series and you will see the entered length of Fibonacci series. 

A Fibonacci In JavaScript is a micro framework for generating different series in different length.

The user has to enter the number for the series length, then click ‘Generate’ button to generate the series.

Also, this Project you can learn on how to Write A Program To Fibonacci Series In JavaScript.

This Program For Fibonacci Series In JavaScript project with source code, also includes a downloadable Fibonacci In JavaScript Code for free, just find the downloadable source code below and click to start downloading.

I have here a suggested list of Best JavaScript Projects with Source Code Free to download and I’m sure this can help you to improve your skills in JavaScript programming and web development as a whole.

To start creating a Fibonacci Series In JavaScript, makes sure that you have any platform in creating a JavaScriptCSS,  bootstrap, and HTML installed in your computer, in my case I will use Sublime Text.

Steps on how to create a Fibonacci Series In JavaScript

Fibonacci Series In JavaScript With Source Code

  • Step 1: Open Sublime Text.

    First after installing sublime text IDE, click “open” to start.
    step 1

  • Step 2: Create a HTML file.

    Second click “file” and select “save as” and named it “index.html
    fibonacci html file

  • Step 3: Create a CSS file.

    Third click “file” and select “save as” and named it “style.cssfibonacci css file

  • Step 4: Create a JavaScript file.

    Fourth click “file” and select “save as” and named it “script.js
    fibonacci javascript file

  • Step 5: The actual code.

    You are free to copy the code given below and paste to your different file created.

The Code Given Below Is For The Index.html Module

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Fibonacci</title>
    <link rel="stylesheet" href="style.css">
    <script src="script.js"></script>
</head>
<body>
    <div class="container">
        <div class="gameDiv">
            <h1>Lets get a Fibonacci sequence: </h1>
            <form action="myForm">
                <input type="number" name="txtNumber" id="txtNumber" id="txtNumber" placeholder="Enter the number...">
            </form>
                <br>
                <button class="button" onclick="Alert.render()">Generate</button>
        </div>
    </div>
    <div id="dialogoverlay"></div>
    <div id="dialogbox">
        <div>
            <div id="dialogboxhead"></div>
            <div id="dialogboxbody"></div>
            <div id="dialogboxfoot"></div>
        </div>
    </div>
</body>
</html>

In this module which is the html file of the system.

The Code Given Below Is For The Style.css Module

body{background-color: #f4f4f4;color: #555555;font: normal 16px Arial, Helvetica, sans-serif;line-height: 1.6em;margin: 0;}

.button{background-color: #333;color:#fff;padding: 10px 15px;border:none;font: bold 16px Arial, Helvetica, sans-serif;}

.button:hover{background-color: red;color: #fff;}

.container{width: 80%;margin: auto;text-align: center;}

.gameDiv{margin: 20px 0;border: 2px dotted #ccc;padding: 20px;border-radius: 20px;}

#dialogoverlay{display: none;opacity: .8;position: fixed;top: 0px;left: 0px;background: #fff;width: 100%;z-index: 10;}

#dialogbox{display: none;position: fixed;background: #000;border-radius: 7px;width: 550px;z-index: 10; }

#dialogbox > div{background: #fff; margin: 8px;}

#dialogbox > div > #dialogboxhead{background: #666;font-size: 19px;padding: 10px;color: #ccc;}

#dialogbox > div > #dialogboxbody{background: #333;padding: 20px;color: #fff;overflow: scroll;}

#dialogbox > div > #dialogboxfoot{background: #666;padding: 10px;text-align: right;}

In this module which is the css file of the system.

The Code Given Below Is For The Script.js Module

function CustomAlert() {
    
    this.render = function() {
        var winW = window.innerWidth;
        var winH = window.innerHeight;
        var dialogoverlay = document.getElementById('dialogoverlay');
        var dialogbox = document.getElementById('dialogbox');
        
        
        var numberEntered = document.getElementById('txtNumber').value;
        var counter = 1;
        var fib = [];

        if (numberEntered == 0) {
            fib = [0];
            document.getElementById('dialogboxbody').innerHTML = fib;
        } else if(numberEntered == 1){
            fib = [1];
            document.getElementById('dialogboxbody').innerHTML = fib;
        } else if(numberEntered == 2){
            fib = [1, 1];
            document.getElementById('dialogboxbody').innerHTML = fib;
        } else if(numberEntered > 2){
            fib = [1, 1];
            while (counter < (numberEntered - 1)) {
                fib.push(fib[counter] + fib[counter - 1]);
                counter++;
            }
            document.getElementById('dialogboxbody').innerHTML = fib;
        }

 
        dialogoverlay.style.display = "block";
        dialogoverlay.style.height = winH+"px";
        
        dialogbox.style.left = (winW/2) - (550 * .5) + "px";
        dialogbox.style.top = "100px";
        dialogbox.style.display = "block";
        
        document.getElementById('dialogboxhead').innerHTML = "Your Fibonacci Sequence is: ";
        // document.getElementById('dialogboxbody').innerHTML = dialog;
        document.getElementById('dialogboxfoot').innerHTML = '<button class="button" onclick="Alert.ok()">OK</button>';
    }
    
    this.ok = function() {
        document.getElementById('dialogbox').style.display = "none";
        document.getElementById('dialogoverlay').style.display = "none";
    }
}

var Alert = new CustomAlert();

In this module which is the JavaScript file of the system.

ABOUT PROJECTPROJECT DETAILS
Project Name :Fibonacci Series In JavaScript
Project Platform :JavaScript
Programming Language Used:php,javascript,html,css
Developer Name :itsourcecode.com
IDE Tool (Recommended):Sublime
Project Type :Web Application
Database:None
Upload Date:October 5, 2020

Downloadable Source Code

Summary

This JavaScript Project With Source Code is simply in HTML, CSS, and JavaScript.

Taking about the features of this system, the user has to enter the number for the series length, then click ‘Generate’ button to generate the series.

This project includes a lot of JavaScript for making the functioning of the project.

Related Articles

Inquiries

If you have any questions or suggestions about Fibonacci Series In JavaScript, please feel free to leave a comment below.

Leave a Comment