Stop Low Resolution Warning Sign

Transcript

Transcript of the tutorial. TOP


          
        
          Okay then.

          So far we've looked at a few different conditions and we've executed code only if those conditions are
          
          true.
          
          But sometimes we want to execute code only if a condition is false.
          
          So normally when we do an if check, we do if then some condition right here and we run the code block
          
          if that condition is true.
          
          That's the way an if statement works.
          
          If whatever is inside here, when it's evaluated is true, then this code block is going to run.
          
          Okay.
          
          Now imagine we have a user variable, and when it's false, it means they're not logged in.
          
          Now I want to make an if check, which is going to run some code.
          
          The code block only when the user is false.
          
          Now, I can't put in here if a user like that and then run some code because this is only going to run
          
          when user is true and I want it to run when user is false.
          
          So how do I do that?
          
          Well, to get around it, we use what's known as the logical not which looks like an exclamation mark.
          
          So when we place an exclamation mark in front of a boolean, so something that's either true or something
          
          that's false, what it does is reverse that boolean.
          
          So if I put it in front of a true value, then it's going to evaluate to false.
          
          If I put it in front of a false value, it's going to evaluate to true.
          
          So let me demo this.
          
          I'm going to console dot log and we're going to console dot log.
          
          True.
          
          And we'll duplicate this and console dot log false.
          
          Okay.
          
          Now then if I run this, we see true and false.
          
          Now what happens if I place exclamation mark and exclamation mark in front of them?
          
          Well, like I said, this is logical.
          
          Not.
          
          And if it's placed in front of true, it takes that value and it turns it on its head.
          
          It makes it false.
          
          Same for this.
          
          It takes the false value and switches it to true.
          
          Okay, so if I save it, we should see false first then true.
          
          And that's what we see.
          
          False then true.
          
          So that's how we switch a boolean value.
          
          So now let's go back to the problem.
          
          I want this to run if the user is false.
          
          Now, normal behavior means that the if statement only runs the code block if whatever is evaluated
          
          in here is true.
          
          Now, currently it's false.
          
          But if I place the logical not or the exclamation mark in front of it, then it's going to switch that
          
          to true.
          
          It's going to evaluate as true the whole statement.
          
          Bear in mind this doesn't actually change the value of user.
          
          User will still always be false.
          
          We're just changing the evaluation here.
          
          We're switching what user is inside these brackets, the outcome of the expression.
          
          So now this whole thing is going to evaluate to true because this is switching the false value.
          
          So now we can say something like console dot log and inside that you must be logged in to continue and
          
          save it.
          
          And if we run this now, we can see this in the console and that's worked because this thing right here,
          
          this exclamation mark, is switching the value of false into true.