Factorialize function not passing the test

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.

Challenge: Factorialize a Number

Link to the challenge:

I ran the same thing you posted and could’t pass the test either

seems like you still need to work onto u code bud

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

@ArielLeslie
Thank You so much It passed !

@KittyKora Fixed it

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));

1 Like

Good job their but, try to censor the outcome :slight_smile: if you can. We don’t want to spoil the answer for others

I’m glad I could help. Happy coding.