Factorialize a number? what is wrong with it?

Tell us what’s happening:

Your code so far


function factorialize(num) {
var factor = 1; 
if (num > 0) {
  for (var i = 1 ; i <= num ; i++) {
    factor = factor * i;
    return factor;
  }
} else {
  return 1;
}
}

factorialize(5);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Factorialize a Number

Link to the challenge:

You have your return statement IN your for loop. This ends the loop on the first iteration, because return shuts down the function.

2 Likes

In the future, If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.