Created
December 29, 2014 15:25
-
-
Save adamdrake210/94386b1d6436b47febc9 to your computer and use it in GitHub Desktop.
My javascript script for the Fibonacci Sequence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fibonacci Sequence - Enter a number and have the program generate the Fibonacci sequence to that number or to the Nth number. | |
var i; | |
var fib = []; | |
fib[0] = 1; | |
fib[1] = 1; | |
document.write(fib[0] + ", " + fib[1] + ", "); | |
var fibonacci = function(n) { | |
for(i=2; i<=n; i++) | |
{ | |
fib[i] = fib[i-2] + fib[i-1]; | |
document.write(fib[i] + ", "); | |
} | |
} | |
fibonacci(100); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment