Factorize a number FCC

Factorize a number FCC
0

#1

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);


#3

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;}”


#4

Hi,

Good explanation here. :slight_smile:


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