Factorialize a Number; Why is this code not working?

Factorialize a Number; Why is this code not working?


Tell us what’s happening:

Your code so far

function factorialize(num) {
  for (i = 1; i <= num; i++) {
     return i *= num;


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.2988.0 Safari/537.36.

Link to the challenge:



when you call return, the function stops,

So basically, here you are doing :

return 1*5

Are you trying to do an iterative or a recursive function ?


I am trying to solve the challenge with a for cycle and for this reason I tried with the code I posted above. In my opinion it is supposed to be iterating until the variable “i” which starts from 1 reaches the number “num” but in fact it ends as you said at 5. So, can you explain to me where my logic goes wrong and how can I rewrite the code so that it does just that?


Here’s a link to the challenge: https://www.freecodecamp.org/challenges/factorialize-a-number


As I told you, the function stops as soon as it reached a return,
You need your for loop to end, so the return call must be after the loop (generally speaking, never put a return call in a loop).

Try to put the return call after the loop.
If you still have struggle with it, I stay around with more hints :slight_smile:


can anyone help me get past this challenge on Basic Algorithm Scripting-Factorialize (5)


i can help you if you are still stuck