const fact = (num) => { // terminal case if (num <= 0) return 1; // block to execute return num * fact(num - 1); }; i.onchange = e => o.value = fact(+e.target.value)
Factorial of <input id="i" style="width:3em"/> = <input id="o" style="width:3em"/>