Then you are not handling the case where x is 0.
Max Stagsted
1

In the process of finding a factorial you should never have to deal with the case of 0. The last step of finding a factorial is multiplication by 1. No matter the number your last step is 1. Once you return 1 to break out of the recursive calls and multiply x by 1 the function is then over and you have your factorial. Try the following against any number and you will always receive the proper factorial with less steps.

function factorial(x) {
if (x === 1) return 1;
return x * factorial(x - 1);
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.