JSFiddle - React, Tailwind, and code Playground

by tom0000p

JavaScript

function fac(x) {
	if(x === 1) return 1;
  
  return x*fac(x-1);
}

function fac(x) 
{
//p = 1. 2 . 3. x(-1).x
	var p = 1;
	for(var i = 2; i <= x; i++)
	{
		p*= i;
	}
  return p;
}

console.log( fac(5) );