Ask coding questions

← Back to all posts
|| Operator Issues and Check for Object(?) Data
AstrumDeorum (136)

I'm trying to check if the opponent is one of the valid types, and then changing damage and stuff accordingly, however it's only checking if the first thing in the check is true, and ignoring everything afterwards.
Sorry if I'm not making any sense, I have zero idea how to phrase any of this and I have no idea to call things.
The code I'm looking at:

var dmg = Math.ceil(Math.random()*10)+5;
    if (
      (teamType == types.Fire && oppoType == ((types.Grass)||(types.Ice)||(types.Bug)||(types.Steel)))
      ||
      (teamType == types.Water && oppoType == ((types.Fire)||(types.Ground)||(types.Rock)))
      ||
      (teamType == types.Grass && oppoType == ((types.Water)||(types.Ground)||(types.Rock)))
    ){
      document.getElementById("actionText").innerHTML=("");
      rollText("actionText", `It's Super Effective!`, 25)
      superSFX.play();
      dmg *= 2;
    }else if (
      (teamType == types.Fire && oppoType == ((types.Water)||(types.Rock)||(types.Fire)||(types.Dragon)))
      ||
      (teamType == types.Water && oppoType == ((types.Grass)||(types.Water)||(types.Dragon)))
      ||
      (teamType == types.Grass && oppoType == ((types.Grass)||(types.Poison)||(types.Bug)||(types.Steel)||(types.Flying)||(types.Fire)||(types.Dragon)))
    ){
      document.getElementById("actionText").innerHTML=("");
      rollText("actionText", `It's Not Very Effective`, 25)
      weakSFX.play();
      dmg /= 2;
      dmg = Math.floor(dmg)
    }else{
      hitSFX.play();
    }
Answered by Coder100 (18208) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (18208)

no, that is not how to check if multiple values are equal to one value!!

Here is how you check!

if (oppoType == types.Fire || oppoType == types.Water || oppoType == types.Rock)

easy

AstrumDeorum (136)

@Coder100 Works like a charm! Thanks!