I've been trying to do something like a game where the users have 3 attempts to guess what number is randomly generated by the code.
The problem is, every time I click on the button, it returns a "Not Found" page.
var numeroSecreto = parseInt(Math.random() * 10)
var tentativas = 3
function funcao(){
var numero=document.getElementById("entrada").value;
while (tentativas > 0) {
if (numeroSecreto == numero) {
document.getElementById("saida").innerHTML="Acertou";
break
} else if (numero > numeroSecreto) {
document.getElementById("saida").innerHTML="O número secreto é menor";
tentativas = tentativas - 1
} else if (numero < numeroSecreto) {
document.getElementById("saida").innerHTML= "O número secreto é maior";
tentativas = tentativas - 1
}
}
if (numero != numeroSecreto) {
document.getElementById("saida").innerHTML="Suas tentativas acabaram o número era: " + numeroSecreto;
}}
<html>
<head>
</head>
<body>
<div = "caixa">
<form>
Digite um número inteiro de 0 a 10:
<input id="entrada">
<button id="botao" onclick="funcao()">Ir</button>
<div id="saida"></div>
</div>
</body>
</html>