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:
), 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.