Fibonacci Sequence in JavaScript
just as the title says
by Joseph Tate
HTML
<h1>Fibonacci sequence</h1>
<input type=text id=number value=3 onchange="$('#output').text(fib($('#number').val()))" />
<p>Output: <span id=output></span></p>
<script>
function fib (n) {
n = parseInt(n, 10);
if (n < 1) {
// error
return 0;
}
if (n===1 || n===2) {
return 1;
}
return fib(n-2) + fib(n-1);
}
</script>