Freecodecamp: Factorial Challenge: Correct, but doesn't register?

Created on 29 Jun 2016  路  5Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Factorialize a Number has an issue.
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

var total = 1;
function factorialize(num) {
  for (var i=0; i<num; i++){
    total = total * (num - i);
  }
  return total;
}

factorialize(5);

Most helpful comment

@LonePoop You just need to declare the 'total' variable inside the function scope.

function factorialize(num) { var total = 1; for (var i=0; i<num; i++){ total = total * (num - i); } return total; } factorialize(5);

All 5 comments

Duplicate of #9199

@LonePoop You just need to declare the 'total' variable inside the function scope.

function factorialize(num) { var total = 1; for (var i=0; i<num; i++){ total = total * (num - i); } return total; } factorialize(5);

Thanks guys!

Thanks all.

Closing in favor of the other thread.

RECURSION GUSY !!, https://msdn.microsoft.com/en-us/library/wwbyhkx4(v=vs.94).aspx
function factorialize(num) {
return (num !== 0) ? num * factorialize(num - 1) : 1;
}

factorialize(5);

Was this page helpful?
0 / 5 - 0 ratings