Using a recursive function to find the factorial of a given integer

I’m trying to make a recursive function to print the factorial of a given integer. Ask the user to enter a positive integer and then display the output on a page. For example, if the user enters 5, the output must be

5 × 4 × 3 × 2 × 1 = 120

var integer = prompt("Enter a positive integer.");
function factorialize(num) {
    if(num == 0 || num == 1) {
        return 1;
    }
    else {
        return num + " x " + factorialize(num-1) + num * factorialize(num-1);
    }
}
document.write(factorialize(integer));

Answer

You can pass a runningTotal of the sum so far to each recursive call. You can also keep the solution compact using template literals.

function factorialize(n, runningTotal = 1) {
  if (n === 1) return `1 = ${runningTotal}`;
  return `${n} x ${factorialize(n - 1, runningTotal * n)}`;
}

console.log(factorialize(5));