0

I am trying to create an application that gives points to a certain item if the user answers in a certain way:

if (question1 == "Red" || "Green"){
        Apple++;
}

Will this setup give the variable apple- which is set to 0- 1 point? I have tried this and it will not work for some reason.

  • 2
    Both sides of the `||` need to involve the comparison to the `question1` variable. – Pointy Jan 26 '20 at 18:24
  • It would be convenient if you could, but no, you have to specify the variable to compare each time. `if (question1 == "Red" || question1 == "Green")` is how you have to do it. What you've written now will be interpreted as `if (question1 == ("Red" || "Green"))` – ADyson Jan 26 '20 at 18:25
  • No, that's not not how either of those operators works, but you could use `["Red", "Green"].includes(question1)` – JLRishe Jan 26 '20 at 18:26
  • Okay, thank you guys! Can you post this separately so I can mark it as a solution? – Someone Randumb Jan 26 '20 at 18:30

0 Answers0