function whoWonGame(){
const winnerSection = ['row1', 'row2', 'row3','column1', 'column2', 'column3', 'dag1', 'dag2' ];
let winner = null;
winnerSection.each((section) => {
let match = true;
for(let i = 1; i <= 2; i++ ){
$(`${section}`).each((div) => {
if(div.hasClass(`player${i}`)){
match = false;
}
})
if(match){
winner = `player${i}`;
}
return winner;
}
})
}
I get an error saying winnerSection.each is not a function. How could that be?
it's Array.prototype.forEach
, not each
.
winnerSection is not a jQuery object. To iterate over an array using .each you must do so:
$.each(winnerSection, function(index, section) {
});
See documentation: http://api.jquery.com/jquery.each/
or use the javascript foreach function: https://developer.mozilla.org/ca/docs/Web/JavaScript/Referencia/Objectes_globals/Array/forEach
winnerSection.forEach(function(section, index) {
});
Caution: the order of parameters of both functions.
I write the code corrected as I think, because selectors and strings used are not correct:
$.each(winnerSection, function(index, section) {
let match = true;
for(let i = 1; i <= 2; i++ ){
$(section).each((div) => {
if(div.hasClass('player'+i)){
match = false;
}
})
if(match){
winner = 'player'+i;
}
return winner;
}
});
winnerSection is not extending jQuery. Try with this:
$(winnerSection).each(.......);
Firebase Cloud Functions: PubSub, "res.on is not a function"
TypeError: Cannot read properties of undefined (reading 'createMessageComponentCollector')
I have a block that calls a bootstrap modal to show an article when left-clicked, I need to add a link to it so a page can be opened when right clicked and "Open in new window" chosenI'm new to bootstrap and I don't know how to even start searching for it
I want to attach a jQuery event handler to a <div> element such that whenever a link is clicked which points to this <div>, that handler is activated and the associated function is executed – regardless of the location of the link (same page, other page, other site) pointing...
I am trying to encrypt a message using BouncyCastle, however I am only getting the correct hash for messages that have a length which is a multiple of 8Is there any way of disabling the padding that happens when the digest method is called?
I need to listen for major changes that happen in user location based on specific location I have and based on distance then show specific message for userI know i can check the location changes using many ways like implement LocationListener or register...