As a beginner in Javascript, I may stumble upon some obvious errors, so please bear with me.
My goal is to iterate through two arrays and perform a loop for each element that exists in both arrays. Currently, this is my code:
if(obtainedCards.some( sp => Boosters.SP.includes(sp)))
{
obtainedCards.forEach(potential => Boosters.SP.includes(potential))
{
// MODIFY THIS TO 0, 100 POST TESTING
this.chance = CardsBetween(76, 100);
console.log(this.chance);
if(this.chance >= 76)
{
this.noOfSPs += 1;
console.log("Test: " + this.chance);
}
};
console.log("Chance is: " + this.chance);
console.log("No of SPs is: " + this.noOfSPs);
//return chance,
return noOfSPs;
}
The initial if
statement functions correctly, but the forEach
does not. It only runs through once even when there are multiple common elements between the arrays.