Hello. I’m trying to complete this algorithm challenge (Factorialize a Number) using a while loop. Can anyone kindly tell me what I am doing wrong here?
function factorialize(num) {
var i = 1;
while (i <= num) {
num = num*(i);
i++;
}
return num;
}
factorialize(5);
Ah, right, the reason it crashes is because you are changing num…
So your condition also changed: i <= 5
But then you do num *= i
So the you have i <= 10 then i <= 30 etc
You have an infinite loop because the condition changes at each iteration
The challenge doesn’t require a while loop, so you are in fact posting working solutions to the challenge. Please wrap the code blocks in spoiler tags so they get blurred.
Oh, the way OP worded it he was specifically speaking about a while loop, my bad. Dont even see my reply here anymore sooo guess someone doesn’t like helping others view problems in a different light so that they’re not always restricted to the same approach for every challenge.
PS: This recent form of strict moderation is not a very welcoming environment especially when solutions are shared as alternatives when OP has already solved the challenge. We should be open to new techniques and approaches and sharing different code to compare and improve.