My code not working on freecodecamp but is ok on jsfiddle

Hey all,

I am a total beginner and I spend a lot of time to figure out what works, I try to progress without hints. It is very very important to me.
Now, there is a quite easy (not for me, though) task, it costed me long hours to solve and it happens not to work on the platform of freecodecamp. However it works on jsfiddle fine.
Could you help me with what I am missing?
Thank you in advance.
Factorial

Please provide a link to the challenge and please copy-paste your code into your post instead of providing a link to an externally hosted image of your code.

Your code is not working because you are using faux-recursion with global variables.


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
1 Like

Thank you JeremyLT for the quick and concise answer!
I will post next time corretly, thank you for that, too.

2 Likes