1
00:00:00,060 --> 00:00:04,770
This lesson, we're going to be looking at our options when we're doing logical operators, where we've

2
00:00:04,770 --> 00:00:09,560
got an option to include more than one condition to check, to see if they are true.

3
00:00:09,570 --> 00:00:15,660
And we also have some flexibility there where we can check to see if both are true and then both need

4
00:00:15,660 --> 00:00:17,960
to be true in order to equate to being true.

5
00:00:17,970 --> 00:00:22,320
Otherwise, it's false, which allows us to check to see if either one of them is true.

6
00:00:22,440 --> 00:00:26,040
And then we've got logical not which returns false.

7
00:00:26,040 --> 00:00:31,230
If a single operand can be converted to true and otherwise it returns true.

8
00:00:31,500 --> 00:00:35,010
So there's more information on this at the Mozilla Developer Network.

9
00:00:35,160 --> 00:00:39,710
They've got some great examples here within the expressions logical operator demo.

10
00:00:39,900 --> 00:00:45,390
So we see that we've got a value of A is set to three, B is set to negative two.

11
00:00:45,600 --> 00:00:50,400
So the condition is checking to see if A is greater than zero.

12
00:00:50,520 --> 00:00:53,120
And for the first one that's going to equate to being true.

13
00:00:53,250 --> 00:00:55,470
But for the second one, that's going to be false.

14
00:00:55,620 --> 00:00:58,590
So that's why we've got an expected output of false.

15
00:00:58,920 --> 00:01:05,580
If we use the word statement and we use the same conditions, we see that this one is true, this one

16
00:01:05,580 --> 00:01:06,210
is false.

17
00:01:06,330 --> 00:01:08,490
So that means that we're getting true returned.

18
00:01:08,640 --> 00:01:13,610
And then we've got the where we've put the exclamation mark where we're negating that.

19
00:01:13,830 --> 00:01:20,610
So because this statement, as we saw over here, is coming out as true, it's negating it.

20
00:01:20,610 --> 00:01:22,470
It's turning it, flipping at the opposite.

21
00:01:22,620 --> 00:01:24,930
So that's why we're being returned back as false.

22
00:01:25,230 --> 00:01:30,090
So there's some great examples here and there's some more explanation about how you can utilize these

23
00:01:30,120 --> 00:01:31,920
within your code as well.

24
00:01:31,950 --> 00:01:38,070
So we do have an exercise challenge for this lesson where we're going to ask the users an age via prompt

25
00:01:38,220 --> 00:01:41,730
and check to see if their age is over 18.

26
00:01:41,880 --> 00:01:48,630
And if they are, then we're going to show the message to allow or deny if they are less than 18 and

27
00:01:48,630 --> 00:01:50,610
we're going to use a ternary operator for that.

28
00:01:50,760 --> 00:01:54,300
And then also checking to see if a user is a member.

29
00:01:54,420 --> 00:01:59,100
So it's going to be a boolean value that the user is a member and then we're going to output a message

30
00:01:59,100 --> 00:02:03,390
to them if they are or if they're not allowing entry to that.

31
00:02:03,480 --> 00:02:09,450
And here's a sneak peek at the code so you can go ahead and pause the video and write out this challenge

32
00:02:09,570 --> 00:02:11,740
and I'll walk you through the solution coming up.

33
00:02:11,760 --> 00:02:15,000
So first thing that we want it to do is capture the user age.

34
00:02:15,000 --> 00:02:17,520
So we set up a variable, declare a variable for that.

35
00:02:17,700 --> 00:02:22,530
And we're going to do that all within one statement where we've got the prompt and that's going to capture

36
00:02:22,530 --> 00:02:27,180
the user's response into the user age value variable.

37
00:02:27,750 --> 00:02:30,540
And you can also output that into the console as well.

38
00:02:30,540 --> 00:02:32,340
So you can just make sure that you've captured it.

39
00:02:33,150 --> 00:02:35,390
We want to convert that into a number.

40
00:02:35,640 --> 00:02:40,380
So if it looks like a number of JavaScript is already going to try to convert it into a number if we

41
00:02:40,380 --> 00:02:43,000
try to use it as a number, but just in case.

42
00:02:43,020 --> 00:02:49,380
So is a good idea to force it and do the conversion type into a number, then we do our check.

43
00:02:49,380 --> 00:02:54,480
So we're going to create a message using the territory operator and that user age value.

44
00:02:54,600 --> 00:03:00,510
And we're checking to see if the age is greater than or equal to 17.

45
00:03:00,750 --> 00:03:05,610
And if it is, then we're going to ask and we're going to do a cloud.

46
00:03:05,610 --> 00:03:11,310
So our message is going to be allow and we can console log out the results of the message as well in

47
00:03:11,310 --> 00:03:11,850
the console.

48
00:03:12,810 --> 00:03:14,710
So try that one and refresh.

49
00:03:14,730 --> 00:03:19,650
So we ask an age and we see that the age comes back as 20.

50
00:03:19,650 --> 00:03:23,510
So we're allowing that age to come through using the territory operator.

51
00:03:23,730 --> 00:03:31,470
And the second part of the challenge was to take our user age and to check to see if they're greater

52
00:03:31,470 --> 00:03:36,620
than seventeen and also if they are user member.

53
00:03:37,260 --> 00:03:47,370
So if this is true, then we can output a message to the console that, yes, allow otherwise its output

54
00:03:47,370 --> 00:03:48,200
of the console.

55
00:03:48,390 --> 00:03:48,810
Nope.

56
00:03:49,260 --> 00:03:52,480
And we're going to do one more value here for the user member.

57
00:03:52,800 --> 00:03:56,000
So first off, we can set user member to be true.

58
00:03:56,550 --> 00:03:59,490
So if all of these conditions are met, we're going to get.

59
00:03:59,490 --> 00:04:06,330
Yes, allow if the person's age is under, we're going to get Dinni and no Denyer so we can add in even

60
00:04:06,330 --> 00:04:07,230
more complex.

61
00:04:08,420 --> 00:04:14,810
And then member can come back here and we can see that there is a value for member or we can check to

62
00:04:14,810 --> 00:04:18,120
see if member is equal to particular value.

63
00:04:18,450 --> 00:04:23,780
It's always good to wrap this with the round brackets so it's more readable, but you don't have to

64
00:04:23,780 --> 00:04:31,250
for the code to work so that we can see that whatever age we enter in here, that we allow it because

65
00:04:31,250 --> 00:04:33,140
the value of member is Lowrance.

66
00:04:33,440 --> 00:04:37,850
So if the value of member is something else, just got in a quick five there.

67
00:04:38,000 --> 00:04:40,850
So even though we get 20, we're not going to be allowed.

68
00:04:40,850 --> 00:04:46,580
So we're allowed to enter because we are of an age, but we don't get entry because we're not a member

69
00:04:46,880 --> 00:04:48,100
within the membership list.

70
00:04:48,860 --> 00:04:53,380
And coming up next, I'm going to have another we're going to have another challenge for you.

71
00:04:53,420 --> 00:04:54,920
So let's come in in the next lesson.
