WEBVTT

1
00:00:00.400 --> 00:00:03.520
Now that we know how to block
on a single specific word.

2
00:00:03.520 --> 00:00:07.030
Let's expand our reach, and
block more than just one offensive word.

3
00:00:07.030 --> 00:00:09.840
Now one trait that we have at our
disposal, is that we can check

4
00:00:09.840 --> 00:00:14.640
multiple conditions by using what is
known as a logical or expression.

5
00:00:14.640 --> 00:00:19.170
Which means we can do something like this,
if the noun is dork, or

6
00:00:19.170 --> 00:00:22.230
the noun is jerk, exit the application.

7
00:00:22.230 --> 00:00:25.300
In fact you could chain these or
statements on forever.

8
00:00:26.430 --> 00:00:28.500
Let's go introduce a logical OR

9
00:00:28.500 --> 00:00:32.700
into your application to block the user
from entering either dork or jerk.

10
00:00:34.430 --> 00:00:37.580
Blocking against the word jerk in
our code is actually pretty easy.

11
00:00:37.580 --> 00:00:41.580
In fact the only thing I think I need to
show you is what OR syntax looks like.

12
00:00:41.580 --> 00:00:44.570
So let's go to our IF statement when
we were checking for dork in the past.

13
00:00:45.800 --> 00:00:50.270
Let's add an OR statement in here, so
we're gonna do a double pipe symbol.

14
00:00:50.270 --> 00:00:51.730
Pipe is above the enter key.

15
00:00:53.280 --> 00:00:58.189
That's what OR looks like so
it's gonna say noun

16
00:00:58.189 --> 00:01:03.585
equals ignore case or
noun equals lowercase on jerk.

17
00:01:05.587 --> 00:01:06.320
Great.

18
00:01:06.320 --> 00:01:10.230
Now this line is getting a little bit long
and in fact if we added one more OR on

19
00:01:10.230 --> 00:01:13.310
here probably go off the screen and then
somebody might not see that it's there.

20
00:01:13.310 --> 00:01:16.980
So one way that we can do to battle
that is because we're inside of this

21
00:01:16.980 --> 00:01:18.490
parenthesis here.

22
00:01:18.490 --> 00:01:22.290
We can add a new line and
take advantage of that space.

23
00:01:22.290 --> 00:01:24.200
So now looks much better.

24
00:01:25.280 --> 00:01:28.617
While we were writing that, one thing that
you might have thought was that you could

25
00:01:28.617 --> 00:01:30.631
do the same thing with two if statements,
right?

26
00:01:30.631 --> 00:01:35.101
You could write this if statement here
you could say equalsIgnore "dork" or

27
00:01:35.101 --> 00:01:39.115
you can make another one that
says if noun.equalsIgnore "jerk".

28
00:01:39.115 --> 00:01:42.154
But what would happen then is that you'd
be writing these same lines inside of

29
00:01:42.154 --> 00:01:45.460
these, this code block here,
you'd be writing that same code twice.

30
00:01:45.460 --> 00:01:47.734
And that's never a good idea.

31
00:01:47.734 --> 00:01:48.860
All right so let's give this a go.

32
00:01:48.860 --> 00:01:53.113
I'm gonna save it and
then I'm gonna compile and run.

33
00:01:55.147 --> 00:01:56.345
I'll say 20.

34
00:01:58.019 --> 00:02:04.540
And we will do big and we're gonna put
in jerk here, great, we caught it.

35
00:02:04.540 --> 00:02:06.190
So let's walk that really quick.

36
00:02:06.190 --> 00:02:09.962
So what we've done here is we have this
first line that's gonna come in here.

37
00:02:09.962 --> 00:02:11.390
It's gonna say noun, and we put in, jerk.

38
00:02:11.390 --> 00:02:12.390
So noun is gonna be jerk.

39
00:02:12.390 --> 00:02:15.780
And it says, if noun equals dork,
and that's a false.

40
00:02:15.780 --> 00:02:16.870
So that's going to say false.

41
00:02:16.870 --> 00:02:20.130
So, false or true.

42
00:02:20.130 --> 00:02:23.730
Right, because noun equals jerk and
it does so we're going to say false or

43
00:02:23.730 --> 00:02:27.070
true and if you imagine that
anytime there's a true in there.

44
00:02:27.070 --> 00:02:28.520
It's gonna be true.

45
00:02:28.520 --> 00:02:30.485
Okay, so
let's make sure that the dork still works.

46
00:02:37.650 --> 00:02:39.640
Awesome it does after using this a bit,

47
00:02:39.640 --> 00:02:42.610
I think we need to do something
different about that exit.

48
00:02:42.610 --> 00:02:46.130
It would be good to give the user
a second chance to enter a nicer word.

49
00:02:46.130 --> 00:02:48.450
Let's see if we can't fix
that in the next lesson.

50
00:02:48.450 --> 00:02:51.070
And one more thing I wanted
to show if you wanted to do

51
00:02:51.070 --> 00:02:53.910
another one of these you can always
chain them with another one.

52
00:02:53.910 --> 00:02:55.399
So right?
So if we wanted to say.

53
00:02:57.731 --> 00:03:02.259
Another guy here, say nerd.

54
00:03:02.259 --> 00:03:07.100
All right perfect and
that is how Ors work.

55
00:03:08.420 --> 00:03:12.570
Great we just learned one way that we
could check multiple conditions in one

56
00:03:12.570 --> 00:03:13.090
IF statement.

57
00:03:14.140 --> 00:03:18.780
By not making two identical code
blocks we avoided repeating ourselves.

58
00:03:18.780 --> 00:03:22.110
A goal of programming is to make sure
that you don't repeat yourself or

59
00:03:22.110 --> 00:03:23.260
often referred to as DRY.

60
00:03:24.690 --> 00:03:28.410
As you advanced through your learnings,
you'll hear this phrase often and I'm sure

61
00:03:28.410 --> 00:03:31.580
it will be hammered into your thinking
as you begin coding bigger applications.

62
00:03:32.720 --> 00:03:34.230
What were you thinking about logic?

63
00:03:34.230 --> 00:03:37.540
I'd like to also introduce you
to ORs counterpart which is AND.

64
00:03:38.650 --> 00:03:42.350
Well OR
returns true if any statement is true and

65
00:03:42.350 --> 00:03:45.450
will only return true if
all expressions are true.

66
00:03:46.480 --> 00:03:49.230
Logical and
use the double ampersand simple

67
00:03:50.520 --> 00:03:54.370
as this logic is such an important
concept and used all over the place.

68
00:03:54.370 --> 00:03:57.182
Let's go back and
review our dating site analogy.

69
00:03:57.182 --> 00:04:01.080
So an example of an OR
statement is must love cats or dogs.

70
00:04:01.080 --> 00:04:04.590
A cat lover would be tested and
she'd say, do you love cats?

71
00:04:04.590 --> 00:04:07.430
And she'd say gee, yes,
yes, yes, yes, yes.

72
00:04:07.430 --> 00:04:11.860
No need to ask about dogs as this
person definitely met the requirement.

73
00:04:11.860 --> 00:04:13.830
Now let's look at another example.

74
00:04:13.830 --> 00:04:18.560
The request is younger than 40 and
has no children and loves art.

75
00:04:18.560 --> 00:04:21.390
This elderly gentleman has
prompted how old he is.

76
00:04:21.390 --> 00:04:25.330
And there is no need to go on asking any
further questions as he doesn't meet

77
00:04:25.330 --> 00:04:26.950
all the conditions.

78
00:04:26.950 --> 00:04:27.730
Okay, so

79
00:04:27.730 --> 00:04:30.630
let's take a really quick exercise
around the statements before we move on.
