Skip to content

Instantly share code, notes, and snippets.

@adamdrake210
Created December 29, 2014 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamdrake210/94386b1d6436b47febc9 to your computer and use it in GitHub Desktop.
Save adamdrake210/94386b1d6436b47febc9 to your computer and use it in GitHub Desktop.
My javascript script for the Fibonacci Sequence
// 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