# Trouble with Factorialize a Number

**URL:** <https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240>\
**Category:** General\
**Created:** [December 19, 2016, 10:22pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240 "2016-12-19T22:22:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nameoferic](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nameoferic](https://forum.freecodecamp.org/u/nameoferic)\
**Post date:** [December 19, 2016, 10:22pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/1 "2016-12-19T22:22:38Z")

</div>

Exactly does how one write the mathematics for factorialization? I guess I’m not sure what to multiply together to get the numbers written next to the red X’s.

---

<div class="post-metadata">

**Author:** ![timotheap](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/timotheap/32/26039_2.png) [@timotheap](https://forum.freecodecamp.org/u/timotheap)\
**Post date:** [December 19, 2016, 10:25pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/2 "2016-12-19T22:25:45Z")

</div>

Hello,

There is a Javascript function that does just that but you’re not supposed to use it. You have to figure out your own function.

So for a given number (for example 5), you have to return 5 \* 4 \* 3 \* 2 \*1 (= 120.)

You have to think logically, and I don’t know if you remember having worked with an accumulator in the previous exercises?

---

<div class="post-metadata">

**Author:** ![nameoferic](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nameoferic](https://forum.freecodecamp.org/u/nameoferic)\
**Post date:** [December 19, 2016, 10:32pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/4 "2016-12-19T22:32:24Z")

</div>

function factorialize(num) {  
num = 1_2_3_4_5_6_7_8_9\*10;  
return num;  
}

factorialize(5);

So something like this.

---

<div class="post-metadata">

**Author:** ![timotheap](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/timotheap/32/26039_2.png) [@timotheap](https://forum.freecodecamp.org/u/timotheap)\
**Post date:** [December 19, 2016, 10:35pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/5 "2016-12-19T22:35:13Z")

</div>

Well that depends on the number. Your code inside the function will work for the number 10.

---

<div class="post-metadata">

**Author:** ![nameoferic](https://avatars.discourse-cdn.com/v4/letter/n/7ea924/32.png) [@nameoferic](https://forum.freecodecamp.org/u/nameoferic)\
**Post date:** [December 19, 2016, 10:37pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/6 "2016-12-19T22:37:27Z")

</div>

So I need to get the function to work for all those numbers. Is this possible with arrays?

---

<div class="post-metadata">

**Author:** ![timotheap](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/timotheap/32/26039_2.png) [@timotheap](https://forum.freecodecamp.org/u/timotheap)\
**Post date:** [December 19, 2016, 10:38pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/7 "2016-12-19T22:38:46Z")

</div>

I’m thinking of a way to explain that but I’m not that comfortable with that challenge 😁

You can look up [here](https://forum.freecodecamp.com/t/algorithm-factorialize-a-number/16013) : you will get several hints to put you on the right tracks.

And if you’re thinking of arrays, then go for it. Whatever works !

---

<div class="post-metadata">

**Author:** ![rschron](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@rschron](https://forum.freecodecamp.org/u/rschron)\
**Post date:** [December 20, 2016, 5:43pm UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/8 "2016-12-20T17:43:48Z")

</div>

By defintion, a factorial is a number multiplied by ever preceding number until 0 is reached. For example:

5! = 5_4_3_2_1

This can be expressed as n! = n \* (n-1) \* (n-2)… \* 1. This is what you want to try and code. One solution could involve a loop. There is another, more elegant solution as well using **_Recursion_** but that’s outside the scope of this course.

---

<div class="post-metadata">

**Author:** ![jwilkins.oboe](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jwilkins.oboe/32/179497_2.png) [@jwilkins.oboe](https://forum.freecodecamp.org/u/jwilkins.oboe)\
**Post date:** [January 16, 2021, 6:10am UTC](https://forum.freecodecamp.org/t/trouble-with-factorialize-a-number/67240/9 "2021-01-16T06:10:59Z")

</div>

Closed on January 16, 2021, 6:10am UTC


