Este es mi codigo, por algun motivo mi programa se crashea cuando lo abro en la web.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<input type="text">
<button>Verificar secreto</button>
<script>
function nAleatorio() {
return Math.round(Math.random()*10);
}
function validar() {
let correcto = false;
for (let i = secretos.length - 1; i >= 0; i--) {
if (secretos[i] === parseInt(adivinanza.value)) {
correcto = true;
alert("valido")
break;
}
}
if (correcto === false) {
alert("invalido")
}
adivinanza.value = "";
// focus hace no se necesite hacer click devuelta en el input
adivinanza.focus();
}
function secretosRandom(tamanho){
let secretos = [];
for (let i = 0; i < sizeArray; i++) {
let numAleatorio = nAleatorio();
//let repetido = false;
for (let j = 0; j <= secretos.length; j++) {
if (secretos[j] === numAleatorio) {
console.log(secretos[i],nAleatorio,"va queriendo");
} else {
secretos.push(numAleatorio);
}
//console.log("Valor de secretos.length: " + secretos.length);
//console.log("Valor de J: " + j);
// if (secretos[i] === secretos[j]) {
// secretos.pop(secretos[i]);
// }
}
console.log(secretos);
}
};
// que el usuario introduzca cantidad de elementos
let sizeArray = parseInt(prompt("Ingrese tamanho array "));
let adivinanza = document.querySelector("input");
let boton = document.querySelector("button");
secretosRandom(sizeArray);
adivinanza.focus();
boton.onclick = validar;
</script>
</body>
</html>