Algorithm Scripting -- Factorialize a Number

Hey guys, I’ve been working on this problem for over an hour today. I know I’m getting close. In fact, my solution even works in Codepen. It just won’t pass the FreeCodeCamp tests. Can anyone help?

Codepen Link:

FreeCodeCamp Challenge Being Discussed:
Code sample:

var result = 1;
function factorialize(num) {
  for (var i = 1; i <= num; i++) {
  if (result!=0) {
  return result;}
  else {
    return 1;


You are using a global variable, as FreeCodeCamp call various times the tests, result change each time

Try adding more than one call and then print result to the console

An other thing you need to consider is
What happens with factorialize(0)