Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created September 5, 2026 09:09
Show Gist options
  • Select an option

  • Save thinkphp/941dca2c5837e4be9a800181d29c63a3 to your computer and use it in GitHub Desktop.

Select an option

Save thinkphp/941dca2c5837e4be9a800181d29c63a3 to your computer and use it in GitHub Desktop.
Front end factorial
<html>
<head>
<script>
function calculateFactorial() {
const number = document.getElementById("number").value;
fetch(`/factorial?number=${number}`)
.then(response => response.json())
.then(data => {
if(data.result) {
document.getElementById("result").innerHTML = `Factorialul lui ${number} este ${data.result}`
} else {
document.getElementById("result").innerHTML = `Eroare: ${data.error}`
}
})
.catch(error => {
document.getElementById("result").innerHTML = "Erorare la obtinera datelor"
})
}
</script>
</head>
<h1>Calcul Factorial</h1>
<p>Introduceti un numar si apasati buttonul pentru a calcula factorialul acestuia </p>
<input type="number" id="number" placeholder="Introduceti un nr">
<button onclick="calculateFactorial()">Calculeaza Factorialul</button>
<div id="result"></div>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment