factorial of a number

前端 未结 28 2417
滥情空心
滥情空心 2020-12-09 11:57

I have the following code but it is not giving perfect result for factorial can u find it out plz



        
28条回答
  •  时光取名叫无心
    2020-12-09 12:39

    1) When X=0 function should return 1; 2) Added return;

     function fact(num)
     {
        var x=parseInt(num);
        //alert(x+1);
        if(x>0)
            x=x* fact(x-1);
        else
            x=1;
        return x;
     }
    

    usage

    
    

提交回复
热议问题