I made a permutation and combination calculator. The code to find the factorial of a number is:
function factorial(num){
total=1;
if(num==1||num==0){
return total;
}
else{
for(i=2;i<=num;i++){
total*=i;
}
return total;
}
}
Here is the code to find permutation:
answer.innerHTML="Answer: "+factorial(n)/factorial(n-r);
If I do 55P9 my answer is .5 off. Everything works if I use Math.floor(), but I want to find the root of the problem.