Tell us what’s happening:
This code, as far as I can tell, factorializes any number given it, took a lot of re-reading and such. But proud of myself.
However the final challenge test is factorialize(0) returns 1, which my code doesn’t pass.
Why is that a condition? Is 0! actually 1 in math? I can’t figure out how to make that happen. Any help appreciated.
Your code so far
function factorialize(num) {
var array = [];
for (num; num >= 1; num--) {
array.push(num);
}
var product = array.reduce(function(previousVal, currentVal) {
return previousVal * currentVal;});
num = product;
return num;
}
factorialize(0);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36
.
Link to the challenge: