<meta charset="utf-8">
</head>
<body>
<input type="text">
<button> Verificar </button>
<script>
var secrets = []
secrets.length = 5
var input = document.querySelector("input")
input.focus()
function definirNumeros(){
for(var i = 0; i<secrets.length; i++){
secrets[i] = Math.round(Math.random() *10);
}
}
function verificar(){
var flag = false;
for( var secret of secrets){
if(parseInt(input.value) == secret ){
alert("Acertaste!" + "El numero era : " + secret)
flag = true;
break;
}else flag = false;
}
if(!flag)
alert("Erraste! intentalo de nuevo")
input.value = ""
input.focus()
}
definirNumeros();
var button = document.querySelector("button")
button.onclick = verificar;
</script>
</body>
</html>