No logro dar con el error de por qué a pesar de ingresar los valores generados en el array siempre me da el mensaje "You're wrong".
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<input/>
<button>Go!</button>
<script>
function random () {
return Math.round(Math.random()*10);
}
function sortNumbers (quantity) {
var secrets = [];
var counter = 1;
while (counter <= quantity) {
randomNumber = random();
secrets.push(randomNumber);
counter++;
}
return secrets;
}
var secrets = sortNumbers(4);
console.log(secrets)
var input = document.querySelector("input");
input.focus();
function verify() {
var guessed = false;
for (var position = 0; position < secrets.lenght; position++) {
if (parseInt(input.value) == secrets[position]) {
alert("You guessed it!");
guessed = true;
break;
}
}
if (guessed == false) {
alert("You're wrong.");
}
input.value = "";
input.focus();
}
var button = document.querySelector("button");
button.onclick = verify;
</script>
</body>
</html>