Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created October 23, 2013 06:25
Show Gist options
  • Save chikoski/7113435 to your computer and use it in GitHub Desktop.
Save chikoski/7113435 to your computer and use it in GitHub Desktop.
<!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>
(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