I'm a beginner, first and foremost.
A final challenge has been proposed in the Alura system in which you have to ask for 6 numbers for a user and draw 6, then compare the arrays to see how many were successful. It's a Mega Sena game.
I want to sort out 6 random numbers that DO NOT repeat. What I've been able to do so far is:
<meta charset="UTF-8">
<script>
var frase = function(texto) {
document.write(texto + "<br>");
}
var sorteados = [];
for(i = 0; i < 6 ; i++) {
var sorteado = parseInt(Math.ceil(Math.random()*60));
sorteados.push();
frase(sorteado);
}
</script>
I would like to insert a if
before each number insertion to check if it already exists in the array, but I have no idea how to do it. I guarantee that I have searched a lot, but nothing answers my question or is extremely complicated for a beginning user like me.