Created
August 27, 2015 17:20
-
-
Save sergiorgiraldo/b4b78c5c80945730434a to your computer and use it in GitHub Desktop.
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
<script type="text/javascript"> | |
function fib(num1, num2){ | |
var sum=num1 + num2; | |
if (sum > upper){ | |
return; | |
} | |
else{ | |
document.write("<br />" + sum); | |
fib(num2, sum); | |
} | |
} | |
var upper = prompt("compute fibonacci until ...","20"); | |
if (!new RegExp("^\\d+$").test(upper)){ | |
document.write("give me a number. you gave me \\" + upper + "\\"); | |
} | |
else if (upper < 1) { | |
document.write("nothing to do here, must be a natural number greater than zero"); | |
} | |
else{ | |
document.write("1<br />1"); | |
if (upper != "1") | |
fib(1,1); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment