Write to function to calculate the factorial of a number

// Function to calculate the factorial of a number
function factorial(n) {
  if (n === 0 || n === 1) {
    return 1;
  }
  return n * factorial(n - 1);
}

// Example usage
const result = factorial(5);
console.log(result);

 

Post your Answer