JavaScript Factorial
- Started
- Last post
- 7 Responses
- dMullins
Working on a little project for a programming course I'm taking. Making good progress in class so far, but we have this little calculator assignment and part of the calculator is to find the factorial of the product of two numbers. I am quite stumped here, and can't figure out what I'm doing wrong (I completed the other math functions successfully at least).
If you have a moment, take a look and let me know if you can help. Extra points if you can explain what I did wrong instead of just the answer:
http://codepen.io/anon/pen/evcFk…
Thanks!
- dMullins0
Enter Q into the prompt to stop the prompt box btw.
- kingsteven0
your function works. no? you just have to enter the same argument for both x and y.
- kingsteven0
BTW: here's the two standard methods of calculating factorials and (if you understand the recursive approach and it's pros/cons, use it. it'll probably get you some bonus points)
- dMullins0
Thanks, buddy. I was trying to get it to work with the product of two numbers instead of having to enter the same number twice. We'll see what happens today.
- dbloc0
is it bad that I don't even know what factorial is?
- kingsteven0
You want to find out how many possible ways you can arrange 3 objects = 3! (exclamation is notation for the factorial) = 3x2x1 = 6
52 objects (ie. a deck of cards) = 52! = 80658175170943878571660636856403...
To find out the probability of any possible hand in 5 card draw = 5!*47!/52! = 2598960
- 'supkingsteven
- obvs you don't need to multiply by 1 and the second answer has been cropped, but you get the idea.kingsteven