- Your function doesn't return anything, ever.
- What do you do when x is 0?
- Minor point - apart from
alert
, you don't really do anything with the returned value.
Try this instead, if you will (hover over the text):
if(x==0) return 1;
return x * fact(x-1);
Working example: http://jsbin.com/apuka3/2