# Factorialize a Number1111

function factorialize(num) {

``````let factor;
let factorelength=[];
for(let i=0;i<=5;i++){
factorelength.push(num-i);

}
for(let j=0;j<factorelength.length;j++)
{
factor*=factorelength[j];

}
return factor;
``````

}

console.log(factorialize(5));

Hi.

for(let i=0;i<=5;i++){
factorelength.push(num-i);
}

It is not right. “i” run until 5? Why 5? And what if it gets other argument?
You want an array that contains one to num.
Now your array contains [5,4,3,2,1,0]. Zero multiplication with something is Zero. So that’s wrong too.

For me going through these challenges, I have to look at what they’re asking, and then think about how to rephrase that as a computer program. I’m still struggling with it, but I think I can help with this.

For a factorial, you need to multiply your argument (num) * every integer lower than it until you get to 1. So the iterations of your for loop need to stem from your argument (num). You put 5 as your threshold for this program, but 5 will only work when you factorialize 5. You need it to apply to any whole number, and luckily for you, that is the argument (num) for the function.

On another note, I would recommend thinking about this in a single for loop. I don’t believe you need to nest anything. I don’t think you need to involve an array either.

You need to have a variable answer, which you then change by multiplying (num) * (num - 1) * (num - 2) * etc until (num - i = 1). The great thing about this for loop is that it’s forgiving. You’re going to stop when you get to multiply by 1, and whether or not you actually multiply by 1 doesn’t matter, because it won’t change variable answer. I’ll give you one more hint: when you initialize your variable, it needs to be a number that can be multiplied by (num) in your first loop through.