Fibonacci Sequence Generator

On September 22, 2015, in Code, Javascript, Work - out of office, by sailesh

Fibonacci Sequence Example: 0, 1, 1, 2, 3, 5, 8, ….

The first two numbers are 0,1. The next number is found by adding up the two numbers before it (0+1). Similarly, the next is found by adding the two numbers before it (1+2).

  • Enter an Upper Limit:
  • Generated Sequence:

Javascript Code:

function generateFib() {
    var limit = 100; // Change the value as you want
    var str = "";
    for (var i = 0, j = 1; i < limit; i = i + j, j = i + j) {
        str = str + (i + ", " + ((j < limit) ? (j + ", ") : ""));
    }
    return (str + "...");
}


 

Leave a Reply

Enable Google Transliteration.(To type in English, press Ctrl+g)