1
I have nine Ivs, three in each row, each div has a span within it with a value. I have created a button that generates random numbers and when the generated number is equal to that of the div it will change its class and when 3 Divs of the same row or column have the same class display a 'Bingo' message. My question is how to make this check if the span’s have the same class to then display the bingo message.
<body>
<h1 class="text-center">Teste Bingo</h1>
<div class="num text-center">
<p id="numSorteio"></p>
</div>
<div class="sorteio col-12 text-center">
<a href="#" id="bt-gerar" class="btn btn-primary text-center btn-randow" >sorteio</a>
</div>
<div class="container">
<div class="row row1">
<div class="col-sm" value="3"><span class="span-bingo n3">3</span></div>
<div class="col-sm" value="8"><span class="span-bingo n8">8</span></div>
<div class="col-sm" value="10"><span class="span-bingo n10">10</span></div>
</div>
<div class="row row2">
<div class="col-sm" value="14"><span class="span-bingo n14">14</span></div>
<div class="col-sm" value="20"><span class="span-bingo n20">20</span></div>
<div class="col-sm" value="28"><span class="span-bingo n28">28</span></div>
</div>
<div class="row row3">
<div class="col-sm" value="32"><span class="span-bingo n32">32</span></div>
<div class="col-sm" value="40"><span class="span-bingo n40">40</span></div>
<div class="col-sm" value="49"><span class="span-bingo n49">49</span></div>
</div>
</div>
var sorteio = document.querySelector('p#numSorteio')
var sortNum = sorteio.innerHTML
var numAleatorio
document.getElementById("bt-gerar").onclick = gerarAleatorio = () =>{
numAleatorio = Math.floor(Math.random() * 50)
sorteio.innerHTML = numAleatorio
var divs = document.querySelectorAll('span'), i;
var div = document.querySelector('span')
for (i = 0; i < divs.length; ++i) {
if(divs[i].innerText == numAleatorio){
divs[i].classList.remove("span-bingo")
divs[i].classList.add("numeroSorteado")
}
}
How would it be possible to give 'bingo' also if the numbers in the same column have the same class . numeroSorteado ?
– Danilo Ferreira
Then you have to ask a new question because it changes the programming.
– Sam