Created
October 23, 2013 06:25
-
-
Save chikoski/7113435 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<form> | |
<input type="text" id="input"> | |
<input type="button" id="btn" value="push to start"> | |
</form> | |
<p id="output"> | |
</p> | |
</body> | |
</html> |
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
(function(){ | |
var fib = function(n){ | |
if(n < 3){ | |
return 1; | |
}else{ | |
return fib(n-1) + fib(n-2); | |
} | |
}; | |
document.getElementById("btn").addEventListener("click", function(event){ | |
var input = document.getElementById("input"); | |
var output = document.getElementById("output"); | |
var n = Number(input.value); | |
var list = []; | |
for(var i = 1; i <= n; i++){ | |
list.push(fib(i)); | |
} | |
output.textContent = list.join(", "); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment