Tell us what’s happening:
The factorialize(num) function seems to be working fine. But still, the tests are not passing
Your code so far
var revarr = [];
var pro = 1;
function factorialize(num) {
for(let i =0; i<num; num--){
revarr.push(num);
}
for (let j =0; j<revarr.length; j++){
pro = pro*revarr[j];
}
return pro;
}
console.log(factorialize(5));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.
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 previous 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
function factorialize(num) {
var revarr = ;
var pro = 1;
for(let i =0; i<num; num–){
revarr.push(num);
}
for (let j =0; j<revarr.length; j++){
pro = pro*revarr[j];
}
return pro;
}
console.log(factorialize(5));