0
Good night. I am building a Javascript Bingo and want to store the numbers already drawn in an array to then consult it and avoid repetitions, but I don’t know how to do this. Can someone help, please?
The code is like this:
<script>
sorteados = [99]
function getBingo() {
var bola = Math.floor(Math.random() * (75 - 1 + 1)) + 1;
sorteados.push(bola);
if (bola < 16) {
letra = "B";
}
else {
if (bola < 31) {
letra = "I";
}
else {
if (bola < 46) {
letra = "N";
}
else {
if (bola < 61) {
letra = "G";
}
else {
if (bola < 76) {
letra = "O";
}
}
}
}
}
document.getElementById("bolinha").innerHTML = "<span style='color:yellow'>" +letra +"</span> "+ bola;
document.getElementById(bola).innerHTML = "<span style='color:red; background-color:white; border-radius:20px; padding:2px;'>" + bola + "</span><audio src='"+bola+".mp3' autoplay></audio>";
}
</script>
<script>document.write ("Números já sorteados: "+sorteados.join(", ")); </script>
The game is running on https://monono.com.br/bingo
I accept suggestions for improvements.
Thank you
This looks like an infinite loop. Have you tried running this function? Run it twice.
– Andre
Yes, I made a mistake using that Isis within the for. Thank you! : D
– João
Thanks, João, but what I can’t do is feed the array with the drawn balls.
– robertomoreno