1
I have nine span, three on each Row, when the 3 spans of the same Row have a certain class I display a message, I would like to know how to make the same logic if the span of the same column have the same class.
<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")
}
}
// busca as rows
var rows = document.querySelectorAll('.container .row');
for(var x = 0; x < rows.length; x++){
if(rows[x].querySelectorAll(".numeroSorteado").length == 3){
// console.log("BINGO na linha "+ (x+1));
sorteio.innerHTML = 'BINGO'
break;
}
}
a doubt: if use
bootstrap
, also not to usejquery
?– Ricardo Pontual
is only for level of knowledge. I’m starting to study javascript and would like to practice a lot with it pure, before leaving for jquery.
– Danilo Ferreira