SwizzleDude SwizzleDude - 2 months ago 9
Javascript Question

Conditional OR statements

How do I implement a test, if a variable equals another, OR another?
I want it to compare the variable "Potato" with the strings "sweet" and "elephant".
Like this here (does not work):

if (Potato === "sweet" or "elephant") { //do stuff }

Answer

Here's what you need to do for working with an "or" condition.

if (Potato === "sweet" || Potato === "elephant") { 
/*your code here*/ 

}

For further reference to JavaScript Comparison and Logical Operators, check this out - http://www.w3schools.com/js/js_comparisons.asp

Comments