Freecodecamp: I got the solution, yet the site will not let me proceed.

Created on 25 Jan 2017  路  2Comments  路  Source: freeCodeCamp/freeCodeCamp

Challenge Factorialize a Number has an issue.
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

var array = [];
var x = 1;
function factorialize(num) {
  for(var i = 1; i <= num; i++);{
    array.push(i);
  }
  for(var j = 0; j < array.length; j++) {
    x = x * array[j];
  } return x;
}

factorialize(9);

Most helpful comment

@joshyu2009 thanks for the issue. You have global variables in your code. Our challenge tests run your function over and over and if you have any global variables, they will change with each test. So move your global variables to within your function and your code will pass. Happy coding!

All 2 comments

@joshyu2009 thanks for the issue. You have global variables in your code. Our challenge tests run your function over and over and if you have any global variables, they will change with each test. So move your global variables to within your function and your code will pass. Happy coding!

I came across the exact same solution and exact same error. Moved the variables to inside the function and it's now recognized as correct answer! Thanks!

Was this page helpful?
0 / 5 - 0 ratings