I am trying to create a function for calculating factorial of a given number. It works fine until I pass a number greater than 21 to the function. I understand that 21! exceeds the max limit of integer, But then is there a solution for that ! Or I am doing something wrong here ! Please help ! Given below is my function for factorial calculation.
function calculateFactorial(number)
{
var counter = 1;
var factorial = number;
if (number == 1) {
factorial = number;
}
else {
while(counter < number)
{
factorial = factorial * (number - counter);
counter++;
}
}
return factorial;
}