Question on recursive functions

Hi guys I am working through the basic javascript algorithms and I can’t understand something.

This is the challenge I am working on.

I can get it to pass the tests when my code looks like this:

function factorialize(num) {

  if (num < 1) { return 1;}

  else {

    return num * factorialize(num - 1);




But when I change the if statement to:

if (num = 0) { return 1;}

It stops working.

I don’t understand why, I mean, num = 0 and num < 1 shouldn’t be the same if num is decreasing by 1 with each call? I am curious to understand why that happens.

Thanks a lot

This is the assignment operator, not a comparison operator.

Of course. I think my brain is fried :rofl:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.