Factorize a number FCC

Hey campers; am currently working on the factorize a number challenge each number works except for zero. this is my code what could be the problem?

function factorialize(num) {
var arr = [];
var singleVal =0;
for(i=1; i<num+1; i++){

arr.push(i);

}

singleVal = arr.reduce(function(a,b){return a*b;});
return singleVal;

}

factorialize(5);

So in short zero is coarsed to null/undefined?..the only way to solve this may to set an if statement “if(num===0){
return 1;}”

Hi,

Good explanation here. :slight_smile:

if (num >= 1) {
        return //put it the factorialize
  }
    return 1;
1 Like