Last active
January 17, 2018 09:41
-
-
Save theWhiteFox/341c569d1bc5abec98fa5b2fb880190d to your computer and use it in GitHub Desktop.
fibonacciWhile
This file contains 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
// 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 += ' ' + 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