# Factorialize a Number Correct answers but not passing

Factorialize a Number Correct answers but not passing
0

#1

Every time I run my code I return the correct answers but for some reason it’s not passing

5 returns 120
10 returns 3628800
and so on.

What is the deal?

Your code so far

``````var array = [];
function factorialize(num) {
for(var i = 1; i < num+1; i++){
array.push(i);

}
var singleVal = array.reduce(function(oldVal, newVal) {
return oldVal * newVal;
},1);
return singleVal;
}

factorialize(0);
``````

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36`.

Link to the challenge:
https://www.freecodecamp.org/challenges/factorialize-a-number

#2

You never defined `array`.

#3

Sorry, i didn’t copy the entire code.

var array = [];
function factorialize(num) {
for(var i = 1; i < num+1; i++){
array.push(i);

}
var singleVal = array.reduce(function(oldVal, newVal) {
return oldVal * newVal;
},1);
return singleVal;
}

factorialize(10);

#4

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.

Example:

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

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

#5

Wow.

I had read through this code a hundred times and didn’t catch that. thank you.