Tell us what’s happening:
So, after a couple hours, I finally got this to work, but it appears like the assignment wants me to use a different method, and instead I used a .push function for i, within the loop, and then used a reduce method to multiply the values.
All of the different values I test seems to come up with the correct result.
What’s the advantage of using recursion instead in this case?
Thanks in advance.
Your code so far
var newArray = [];
function factorialize(num) {
if (num === 0) {
return 1;
}
else {
for (var i = 1; i < (num + 1); i++)
{
newArray.push(i);
}
{
num = newArray.reduce(function(previousVal, currentVal) {
return previousVal * currentVal;
});
}
return num;
}
}
factorialize(10);
**Your browser information:**
Your Browser User Agent is: ```Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36```.
**Link to the challenge:**
https://www.freecodecamp.org/challenges/factorialize-a-number