<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>adivinacion</title>
</head>
<body>
<h4>Digite un numero del 0-10</h4>
<input type="text">
<button>VERIFICAR</button>
<script>
function saltarLinea() {
document.write("<br>");
document.write("<br>");
}
function imprimir(frase) {
document.write(frase);
saltarLinea();
}
var numeroPensado = Math.round(Math.random()*10);
var numLanzado = document.querySelector("input");
var intentos = 3;
var intentos_usados = 1;
var cont = 1;
numLanzado.focus();
function verificar(){
while(cont <= intentos){
if (parseInt(numLanzado.value) == numeroPensado) {
alert("usted acertó en el intento " + intentos_usados + " El numero era: " + numeroPensado);
imprimir("en horabuena acertaste");
break;
}
else{
alert("Usted erro, intento: " + intentos_usados);
intentos--;
intentos_usados++;
break;
}
cont++;
}
if (intentos == 0) {
imprimir("Se agoto el numero de intentos");
}
numLanzado.value = "";
numLanzado.focus();
}
var button = document.querySelector("button");
button.onclick = verificar;
</script>
</body>
</html>