I’ve been trying to figure out Factorialize a Number algorithm from the Javascript Algorhithms and Data Structures course and I’m kind of stuck. I understand hinted solutions but I don’t get why mine doesn’t work:
function factorialize(num) {
for (let i = 1; i < num; i++) {
num = num * i;
}
return num;
}
factorialize(5);
The console output is obviously failed test along with this massage : “Potential infinite loop detected on line 3. Tests may fail if this is not changed.” Which to be honest I don’t quite understand as the description of the challenge says that “Only integers greater than or equal to zero will be supplied to the function.” Even if you’d pass the 0 or -5 or whatever then the condition part of a for loop definition simply evaluates to false and the function should return unaltered value back.