Complex Conditions

By: Dusty Arlia
Published on October 30, 2012
Last Updated on Monday, July 06, 2015 at 2:21 PM
Total Updates: 3

Complex conditions are conditions that have multiple conditions. To do this, complex conditions usually use a logical AND operator (&&) and/or a logical OR operator (||) to combine multiple conditions. Complex conditions are typically used to evaluate received information to find certain values. A common piece of information that gets evaluated a lot is email address fields in forms. When you're evaluating a string that is supposed to be an email address, you need to make sure that there is an @ symbol and a period in the string.

Here is an example of a complex condition using the logical AND operator:

if ((price > 5) && (weight < 20)) {
alert('Shipping is free!');
}

Here is an example of a complex condition using the logical OR operator:

if (customer == 'senior' || customer == 'veteran' || customer == 'Chuck Norris') {
alert('You get 50% off!');
}

Comments:

Ad: