This lesson, we're going to be looking at our options when we're doing logical operators, where we've
got an option to include more than one condition to check, to see if they are true.
And we also have some flexibility there where we can check to see if both are true and then both need
to be true in order to equate to being true.
Otherwise, it's false, which allows us to check to see if either one of them is true.
And then we've got logical not which returns false.
If a single operand can be converted to true and otherwise it returns true.
So there's more information on this at the Mozilla Developer Network.
They've got some great examples here within the expressions logical operator demo.
So we see that we've got a value of A is set to three, B is set to negative two.
So the condition is checking to see if A is greater than zero.
And for the first one that's going to equate to being true.
But for the second one, that's going to be false.
So that's why we've got an expected output of false.
If we use the word statement and we use the same conditions, we see that this one is true, this one
is false.
So that means that we're getting true returned.
And then we've got the where we've put the exclamation mark where we're negating that.
So because this statement, as we saw over here, is coming out as true, it's negating it.
It's turning it, flipping at the opposite.
So that's why we're being returned back as false.
So there's some great examples here and there's some more explanation about how you can utilize these
within your code as well.
So we do have an exercise challenge for this lesson where we're going to ask the users an age via prompt
and check to see if their age is over 18.
And if they are, then we're going to show the message to allow or deny if they are less than 18 and
we're going to use a ternary operator for that.
And then also checking to see if a user is a member.
So it's going to be a boolean value that the user is a member and then we're going to output a message
to them if they are or if they're not allowing entry to that.
And here's a sneak peek at the code so you can go ahead and pause the video and write out this challenge
and I'll walk you through the solution coming up.
So first thing that we want it to do is capture the user age.
So we set up a variable, declare a variable for that.
And we're going to do that all within one statement where we've got the prompt and that's going to capture
the user's response into the user age value variable.
And you can also output that into the console as well.
So you can just make sure that you've captured it.
We want to convert that into a number.
So if it looks like a number of JavaScript is already going to try to convert it into a number if we
try to use it as a number, but just in case.
So is a good idea to force it and do the conversion type into a number, then we do our check.
So we're going to create a message using the territory operator and that user age value.
And we're checking to see if the age is greater than or equal to 17.
And if it is, then we're going to ask and we're going to do a cloud.
So our message is going to be allow and we can console log out the results of the message as well in
the console.
So try that one and refresh.
So we ask an age and we see that the age comes back as 20.
So we're allowing that age to come through using the territory operator.
And the second part of the challenge was to take our user age and to check to see if they're greater
than seventeen and also if they are user member.
So if this is true, then we can output a message to the console that, yes, allow otherwise its output
of the console.
Nope.
And we're going to do one more value here for the user member.
So first off, we can set user member to be true.
So if all of these conditions are met, we're going to get.
Yes, allow if the person's age is under, we're going to get Dinni and no Denyer so we can add in even
more complex.
And then member can come back here and we can see that there is a value for member or we can check to
see if member is equal to particular value.
It's always good to wrap this with the round brackets so it's more readable, but you don't have to
for the code to work so that we can see that whatever age we enter in here, that we allow it because
the value of member is Lowrance.
So if the value of member is something else, just got in a quick five there.
So even though we get 20, we're not going to be allowed.
So we're allowed to enter because we are of an age, but we don't get entry because we're not a member
within the membership list.
And coming up next, I'm going to have another we're going to have another challenge for you.
So let's come in in the next lesson.