Tell us what’s happening:
So the first problem is that my code does work, but it seems to me that my solution is wrong. The second problem is that thecode (you can see the code below in Your code so far ) doesn’t work in my console. But if I declare ‘sum’ and ‘arrFac’ before function it works. I don’t understand why does it happen.
Your code so far
function factorialize(num) {
let sum = 1
let arrFac = []
for(let i = num; i>0; i--){
arrFac.push(i)
sum *=i
}
return sum;
}
factorialize(5);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 YaBrowser/19.12.0.358 Yowser/2.5 Safari/537.36.
I wrote code in Visual studio code, and when I open file from VS code in my console it doesn’t work.
But if I declare variables before function it works.
For the second one, you do not have console.log(factorialize(5)); like your first example. It has nothing to do with where you put the variable declarations.
but you are already multiplying the numbers before putting them all in the array, do you really need the array? you are not doing anything with the array