Good morning, I created a small lottery game, where 06 numbers are generated between 0-20, the user informs his guess of 06 numbers and the system returns how many numbers were hit and which numbers hit.
The problem is that the randomly generated numbers have repetition, do I want suggestions on how I can solve this problem so that the code is more reliable? Thanks for any help.
<script type="text/javascript">
jogo = [];
sorteio = [];
acertos = [];
i = 1;
while(i<=6){
jogo.push(Math.round(Math.random()*20));
sorteio.push(parseInt(prompt("Informe a "+i+"ª Dezena!")));
i++;
};
for (var i = 0; i<jogo.length; i++) {
if(sorteio.indexOf(jogo[i])>-1){
acertos.push(jogo[i]);
}
};
alert("Sorteio: "+jogo+"\nAposta: "+sorteio+"\nVocê acertou " + acertos.length + " números: "+ acertos);
console.log(jogo);
console.log(sorteio);
console.log(acertos);
console.log("Você acertou " + acertos.length + " números: ", acertos);
</script>