Without a stopping condition the recursion runs away, so a guard is used here instead.
Acceptance criteria
- 1.#out should show result 120.
Without a stopping condition the recursion runs away, so a guard is used here instead.
function fact(n, depth = 0) { if (depth > 20) return 1; return n * fact(n - 1, depth + 1); } document.querySelector('#out').textContent = "result " + fact(5);
Output ready when you are
Press Run to render your code, or Submit to validate your solution.