Recursive return 0?

Can anyone explain why in the if for the recursion solution,

if return 1 would get 120
if return 2 would get 240
if return 0 get 0 ?

why would the logic would be 0 and not 120??

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

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

function factorialize2(num) {
 let product = 1;
  for(let i = 2; i <= num; i++){
    product *= i;
  }
    return product;
}

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

console.log(((1*2*3*4*5)+0))

console.log(
totalNum(5));

console.log(
factorialize(5));

console.log(
factorialize2(5));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36

Challenge: Factorialize a Number

Link to the challenge:

The factorial of 1 is 1. The factorial of 2 is 2. So I’m not sure where you are getting 120 and 240? Perhaps I don’t understand exactly what you are asking. Can you try to explain a little more clearly?

The factorial 0 is 1. Again, I’m not sure why you think it would be 120?

Remember that anything times zero is zero (a knowledge bomb :grinning:), so if you return zero at the final step as you return back through all the steps it will be “zero * something” or always zero.

boom!! i see if +0 would do would 15
+1 16, …

*0 0 , 1 120 , 2 240

arrr… thats how it made of. so all return will sum it up !

thanks, you good! :kissing_smiling_eyes:

thanks,

i realise the code
function totalNum(num){
if(num === 0){

return 1;
} else {
return num * totalNum(num- 1)
}

return 1 , result 120.

if i change to return2 , in the console it show 240.