<input/>
<button>Compare com o meu segredo</button>
<script>
function sorteia() {
return Math.round(Math.random() * 10);
}
function sorteiaNumeros(quantidades) {
var segredos = [];
var numero = 1;
while(numero <= quantidades) {
var numeroAleatorio = sorteia();
var achou = false;
if(numeroAleatorio ==! 0) {
for(var posicao = 0; posicao < segredos.length; posicao++) {
if (numeroSorteado == segredos[posicao]) {
achou = true;
break;
}
}
if(achou = false) {
segredos.push(numeroAleatorio());
numero++;
}
}
}
return segredos;
}
var segredos = sorteiaNumeros(3);
console.log(segredos);
var input = document.querySelector("input");
input.focus();
function verifica () {
var achou = false;
for(var posicao = 0; posicao < segredos.length; posicao++) {
if(input.value == segredos[posicao]) {
alert("Você acertou!");
achou = true;
break;
}
}
if(achou == false) {
alert("Você errou!");
input.focus();
input.value = ""
}
}
</script>