Skip to content

Instantly share code, notes, and snippets.

@hjJunior
Last active June 22, 2020 23:55
Show Gist options
  • Save hjJunior/5db60d587d41f5f60e0544d0502b1337 to your computer and use it in GitHub Desktop.
Save hjJunior/5db60d587d41f5f60e0544d0502b1337 to your computer and use it in GitHub Desktop.
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