Javascript Tutorial – fibonacci sequence with For statement




Copy the code over here! http://betacoding.net/javascript/javascript-programming-fibonacci-sequence-with-the-for-statement
__________________
Thank you for watching this video, if you like it please don’t forget to like it,
or subscribe to my channel for more programming tutorials

also visit my website for more content
http://betacoding.net

Original source


12 responses to “Javascript Tutorial – fibonacci sequence with For statement”

  1. Try with this very simple and results will display in horizontal…I modified above betacoding
    var fibonacci_series = function (n)
    {
    var a=0,b=1,f=b,s =[0,1];
    for(var i=0;i<n;i++) {
    f= a+b;
    s.push(f);
    a=b;
    b=f;
    }
    return s;
    };
    fibonacci_series(n)

  2. Isn't 0 considered fibonacci number? If you replace a=0 to a=1 and b=1 to b=0 it will print all numbers from 0.

    var a, b, result;
    a = 1;
    b = 0;
    result = b;
    for (var i=1; i<=20; i++) {
    document.write(result+"<br/>");
    result = a + b;
    a = b;
    b = result;
    }

  3. Not working :
    if you ask for results over a 100, numbers start showing incorrectly.
    if you ask for result over 1478, numbers are replaced by the word "infinity".

    … No use, but nice try though !

Leave a Reply