1 00:00:00,398 --> 00:00:03,975 You learned to use the and operator to perform an action of two or 2 00:00:03,975 --> 00:00:06,013 more conditions evaluate to true. 3 00:00:06,013 --> 00:00:09,620 There are times you'll want to perform an action if either of two possible 4 00:00:09,620 --> 00:00:10,735 conditions are true. 5 00:00:10,735 --> 00:00:16,285 For example, if it's hot or the indoor pool is open, then I'll go swimming. 6 00:00:16,285 --> 00:00:18,797 In this case, either condition can be true. 7 00:00:18,797 --> 00:00:22,892 It might be really cold outside, but the indoor pool is heated and warm, so 8 00:00:22,892 --> 00:00:23,997 I'll go swimming. 9 00:00:23,997 --> 00:00:27,891 On the other hand, the indoor pool may be closed but it's hot so 10 00:00:27,891 --> 00:00:29,887 I'll go swimming in the ocean. 11 00:00:29,887 --> 00:00:33,353 To run this type of test, you use the or operator. 12 00:00:33,353 --> 00:00:38,147 It's called or because the entire condition returns true if either 13 00:00:38,147 --> 00:00:41,856 condition one or condition two evaluates the true. 14 00:00:41,856 --> 00:00:46,007 The logical or operator is represented by two pipe characters. 15 00:00:46,007 --> 00:00:49,789 On most keyboard, the pipe characters is on the same key as the backslash. 16 00:00:49,789 --> 00:00:52,086 Hold down the shift key to type it. 17 00:00:52,086 --> 00:00:54,836 All right, let's see how the or operator works. 18 00:00:54,836 --> 00:00:57,296 Say you let someone agree to the terms and 19 00:00:57,296 --> 00:01:01,283 service of your website by typing either yes or just the letter Y. 20 00:01:01,283 --> 00:01:03,888 They can type either one or other. 21 00:01:03,888 --> 00:01:09,586 Back in the console, I'll store the response in a variable named agree and 22 00:01:09,586 --> 00:01:11,587 assign it the string yes. 23 00:01:11,587 --> 00:01:15,212 I can then use the logical or operator like this. 24 00:01:15,212 --> 00:01:19,742 Agree strictly equals yes or 25 00:01:19,742 --> 00:01:23,900 agree strictly equals y. 26 00:01:23,900 --> 00:01:26,526 Just like with the logical and operator, 27 00:01:26,526 --> 00:01:29,610 there's really two separate conditions here. 28 00:01:29,610 --> 00:01:34,856 Each condition gets tested separately and produces its own true or false values. 29 00:01:34,856 --> 00:01:37,625 The value in the agree variable is yes. 30 00:01:37,625 --> 00:01:42,896 So the first test asks if yes is strictly equal to yes, it is. 31 00:01:42,896 --> 00:01:45,378 So this first condition is true. 32 00:01:45,378 --> 00:01:51,348 The second test asks if yes is strictly equal to y, this is not true. 33 00:01:51,348 --> 00:01:56,940 The role of the or operator here is to ask if condition one is true or 34 00:01:56,940 --> 00:01:58,780 condition two true. 35 00:01:58,780 --> 00:02:00,879 In this case, one is true and 36 00:02:00,879 --> 00:02:05,087 that's enough this entire condition evaluate to true. 37 00:02:05,087 --> 00:02:07,171 Let's continue with two more examples. 38 00:02:07,171 --> 00:02:13,156 I'll change the value and agree to just y. 39 00:02:13,156 --> 00:02:18,095 Now the first condition is false, y is not equal to yes, 40 00:02:18,095 --> 00:02:22,309 but the second condition y is equal to y is true. 41 00:02:22,309 --> 00:02:24,933 So the entire condition is also true. 42 00:02:24,933 --> 00:02:29,636 Remember, just the one test needs to pass. 43 00:02:29,636 --> 00:02:34,503 What if I set the value of agree to n? 44 00:02:34,503 --> 00:02:38,641 The first condition is false, and the second condition is also false. 45 00:02:38,641 --> 00:02:41,641 In this case, because neither condition is true, 46 00:02:41,641 --> 00:02:44,167 the whole condition evaluates the false. 47 00:02:44,167 --> 00:02:48,772 Keep in mind that you need to create complete conditions on either side of 48 00:02:48,772 --> 00:02:49,905 the or operator. 49 00:02:49,905 --> 00:02:53,558 For example, you can't do something like this. 50 00:02:53,558 --> 00:02:57,316 Even though it feels like this should be correct, 51 00:02:57,316 --> 00:03:01,167 it really reads like, if agree is equal to yes or y. 52 00:03:01,167 --> 00:03:05,986 Whatever appears on either side of the or operator has to be a complete condition. 53 00:03:05,986 --> 00:03:08,393 Y by itself isn't really condition. 54 00:03:08,393 --> 00:03:13,054 So remember, you need to have full conditions on either side. 55 00:03:13,054 --> 00:03:15,968 In the logical end and or operator examples, 56 00:03:15,968 --> 00:03:20,045 I've used just two conditions and a single logical operator. 57 00:03:20,045 --> 00:03:23,419 You can actually have more than one of each operator. 58 00:03:23,419 --> 00:03:28,280 For example, you can test if condition one is true, and condition two, 59 00:03:28,280 --> 00:03:30,525 and condition three, and so on. 60 00:03:30,525 --> 00:03:34,311 There's no limit to the number of logical and operators you string together. 61 00:03:34,311 --> 00:03:39,329 Just remember that with the and operator, every single condition must be true for 62 00:03:39,329 --> 00:03:41,957 the entire condition to evaluate to true. 63 00:03:41,957 --> 00:03:46,362 If just one of the conditions is false, then the entire condition is false. 64 00:03:46,362 --> 00:03:49,901 You can also string together multiple logical or operators. 65 00:03:49,901 --> 00:03:53,537 In this case, only one of the conditions needs to be true for 66 00:03:53,537 --> 00:03:56,609 the entire larger condition to evaluate to true. 67 00:03:56,609 --> 00:04:00,834 And this example, if any of these three variables contains an empty string, 68 00:04:00,834 --> 00:04:02,790 then the entire condition is true.