SPOILER! Factorialize a Number

Hello, I was wondering if this code is any different from the answer provided by FCC. Is there any difference or benefits writing it the way FCC did, or is mine fine as well?

This is the FCC answer, my answer is after this:

function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);

Your code so far

function factorialize(num) {
  if (num!==0) {
    return num*factorialize(num-1);
  else {
    return 1;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:

no difference.

if num !== 0 the lines will just get stepped over

Thanks for clarifying ^^

Normally, if you write anything recursive there is a convention that you need to declare ‘exit condition’ at the start. Considering this, FCC code is more correct

1 Like

Ahh I see! Thanks so much, I will take note of that :smile: