Factorialize a Number - Help

var p = 1;
function factorialize(num) {
  for (var i = num; i > 0; i--) {
    p *= i;
  return p;

If I put the test numbers in, I get the correct answer in the console. Why is it not passing the tests?

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the new value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2