var temp = 1 function test(num){ while(num){ temp = temp*num num-- } return temp } console.log(test(5)) function test2(num){ if(num<=1){ return 1 } else{ return num*test2(num-1) } } console.log(test2(5))