I'm doing a guessing game in JavaScript where the user has three attempts to guess a random number between 1 and 10, but during the test, whenever I fail the first try, I increment the tentative variable, but the code finishes rolling. What am I missing?
Follow the code
var chute = document.getElementById("chute")
var numero
var tentativa
function aleatorio() {
numero = parseInt(1 + Math.random() * 10)
var chute2 = parseInt(chute.value)
tentativa = 0;
if (chute2 != numero || tentativa != 2) {
alert("Você errou! Tente de novo")
document.getElementById("adivinha_form").reset();
} else if (chute2 != numero && tentativa == 2) {
alert("Suas chances acabaram! O número correto é " + numero)
} else if (chute2 == numero) {
alert("Parabéns! Você acertou")
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Adivinhador</title>
</head>
<body>
<h1>Adivinhador</h1>
<form name="adivinha" id="adivinha_form" action="#">
<p>
Seu chute: <br>
<input type="text" id="chute" name="chute">
</p>
<button onclick="aleatorio()" reset="true">Arriscar</button>
</form>
<script type="text/javascript" src="adivinhacao.js"></script>
</body>
</html>