Basic Algorithm Scripting - Factorialize a Number

This is one heck of a challenge because i know what i have to do but i dont know how. I understand that i need to set a function that verifies if an integer is greater than or equal to zero. Which i think it will be represented like this
if (num >= 0) and somehow, i dont know how, it has to return each number that is not equal to zero and multiply each result, until that number is 1 and then the function will return 1.
Im a bit very lost because i dont want to look for the answer online yet i dont know how to code what i have in mind, which is for a function to substract 1 to the initial number each time that the number is not equal to 0 or 1, and for each and every number to be multiplied. I tried reading the help article but it wasnt very useful to me.

Your code so far

function factorialize(num) {
  if (num >= 1){
    return ;
  } else {
    return 1
  }
  }
  return num;
}

factorialize(5);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Basic Algorithm Scripting - Factorialize a Number

Link to the challenge:

Are you trying to use a recursive solution to this problem? If that isn’t making sense then you don’t have to do it recursively.

Seems like you need a loop in your solution.

Try for / while loop >> JavaScript for Loop

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.