Skip to content

Instantly share code, notes, and snippets.

@theWhiteFox
Last active January 17, 2018 09:41
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 theWhiteFox/341c569d1bc5abec98fa5b2fb880190d to your computer and use it in GitHub Desktop.
Save theWhiteFox/341c569d1bc5abec98fa5b2fb880190d to your computer and use it in GitHub Desktop.
fibonacciWhile
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
// 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
// Fn = Fn-1 + Fn-2
// F0 = 0, F1 = 1
"use strict";
// fibonacci html output
function fibonacciHTML() {
var result = 0, term1 = 0, term2 = 1, i = 1;
var text = term1 + ' ' + term2;
while(i < 10) {
result = term1 + term2;
text += '&nbsp;' + result;
term1 = term2;
term2 = result;
i++;
}
return text;
}
// error in console document.getElementById(...) is null
window.onload = function() {
document.getElementById("fibWhile").innerHTML = fibonacciHTML();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment