Last active
June 22, 2020 23:55
-
-
Save hjJunior/5db60d587d41f5f60e0544d0502b1337 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
const factorial = (number) => { | |
if (isNaN(number)) { | |
throw new Error(`"${number}" não é uma entrada valida`); | |
} | |
if (number == 0) { | |
return 1 | |
} | |
return number * factorial(number - 1); | |
} | |
const userInput = prompt("Digite um número: "); | |
const parsedNumber = parseInt(userInput); | |
const factorialResult = factorial(parsedNumber); | |
document.write(`O fatorial de ${userInput} é ${factorialResult}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment