trying to calculate a factorial with recursion. I don't think I'm getting the variable back and forth to javascript correctly.
<!DOCTYPE html>
<html>
<body>
<h1>
Factorial
</h1>
Enter Number <input type="number" id="myNumber" value="">
<button onclick="myFunction()">Result</button>
<p id="demo"></p>
<script>
function myFunction() {
let x = document.getElementById("myNumber").value;
if (x === 0)
{
return 1;
}
return x * factorial(x-1);
}
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>