I have the following code but it is not giving perfect result for factorial can u find it out plz
function factorial(n) { return (n != 1) ? n * factorial(n - 1) : 1; } alert( factorial(5) );
You can try to use recursion method