Running it on Repl.it, I get the right answers for the FreeCodeCamp’s tests (
`factorialize(5)` should return 120.
`factorialize(10)` should return 3628800.
`factorialize(20)` should return 2432902008176640000.
`factorialize(0)` should return 1.
, but I can’t pass FreecodeCamp’s tests.
I know the below isn’t elegant (saw the recursive answer on hint by now, but code below works). This is my code:
let i = 1
function factorialize(num) {
let fact = num;
if (num == 1) {
fact = 1;
}
if (num == 0) {
fact = 1;
}
while (i < num) {
fact *= (num-i) ;
i++
}
return fact;
}
Super, I’ll keep in mind trying out the variable declaration (for the sake of passing the test). And thanks for the note on placing a return earlier, appreciated.