I do not understand the question of Factorialize a Number

Tell us what’s happening:

Hi, Campers!

I am on a Factorialize a Number but I do not understand the question or how to do it. Please advise.

Thank you!

Your code so far

function factorialize(num) {
  return num;
}

factorialize(5);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/factorialize-a-number

Do you know how to calculate 5! (5 factorial) on paper? You will need to generate the product of all the applicable numbers using some type of iterative solution (using a loop of some kind) or a recursive solution.

Here is a wiki on factorial.

I feel so stupid still not understand it.

0! is 1
1! is 1
2! is 2 * 1 which = 2
3! is 3 * 2 * 1 which = 6
4! is 4 * 3 * 2 * 1 which = 24
5! is 5 * 4 * 3 * 2 * 1 which = 120
and so on

Another way of looking at it is
n! = n * (n-1) * (n-2) * … 2 * 1
Using 5! as an example that would be
5! = 5 * (5-1) * (5-2) * (5-3) * (5-4) or 5 * (4) * (3) * (2) * (1) which is the same as I showed before. You just have to figure out an algorithm which produces this same result.

You could take the iterative approach first and have a for loop which starts a n and continues down to 1 and have a variable which contains the cumulative product. After the for loop is finished, you would return this variable because it would have the final answer. You just need to figure out a starting value for the cumulative product value. Hint: It will not be zero, because zero multiplied by any number would be zero for the entire loop.

1 Like

What number with ! after means anyway?

Hi Krittiyaclark,

! is just a mathematical symbol like +, -, etc. It means do the factorial operation, which randelldawson outlined how to do in his post pretty well. It is sort of like a countdown but you are multiplying your way down the numbers.

Hope my 2 cents helps.