Stop Low Resolution Warning Sign

Transcript

Transcript of the tutorial. TOP


          
        
          Currently we're checking if a password is at least eight characters long.

          Now, if it is, then it's going to run this code block and output this.
          
          If it's not if this is false, for example, if this is four, five, 6 or 7 or something like that,
          
          characters long, then it doesn't run this code.
          
          Block Now, it would be good to run a different code block if that condition right here is not met.
          
          So we can offer some feedback to the user.
          
          Something like the password is not long enough now to do that.
          
          We use an else statement.
          
          So at the end of the first code block after the if check, we can say else then open up a new code block
          
          and fire this if that first condition is not true.
          
          So it checks this.
          
          If it's true, it fires this code block and not this.
          
          If it's not true, then it doesn't fire this code.
          
          Block But it does fire this instead.
          
          This is the else clause.
          
          Okay?
          
          So what we could say is console, dot log and then say password is not long enough.
          
          All right?
          
          So save that.
          
          And since this is currently four characters long, it should be the else code block that fires and not
          
          this one.
          
          So let's check that over here.
          
          Password is not long enough and notice it's only ever going to run either one of these code blocks.
          
          Either this or this.
          
          Never both of them.
          
          Okay.
          
          If this is true, it only runs this and it ignores the else case.
          
          If this is false, it only runs this and ignores this case.
          
          Now, sometimes we might want to check multiple different conditions.
          
          So say, for example, we still want to check the password, but we want to check first of all, is
          
          the password at least 12 characters long?
          
          If it is, then will output a message that says this password is super strong or mighty strong or something
          
          like that.
          
          If it's not, then we'll do another check.
          
          Is the password at least eight characters long?
          
          If it is, we'll output this.
          
          If it's not, then we'll catch it right here and run the else statement.
          
          So again, only one code block will ever run, but this time we're going to check multiple different
          
          conditions.
          
          So how do we do that?
          
          Well, let's start at the top.
          
          We're going to check, first of all, if the password dot length is greater than or equal to 12 characters
          
          long, If this is the case, then we're going to console dot log.
          
          That password is mighty strong.
          
          Okay.
          
          So that's the first condition.
          
          Now we also want to check the second condition, but we only want to check this if this is false.
          
          So we can't just leave it here because if it's 12 characters long currently, then it's going to run
          
          this and output this.
          
          Then it's going to come down here and it's going to run this as well.
          
          We don't want that.
          
          We want one or the other.
          
          So instead of creating a new if case, we instead bring this back up and do else if okay, so we say,
          
          if this is true, run this.
          
          If it's not, then go down to the next clause.
          
          Else if and another condition.
          
          If this is true, we run this.
          
          If it's not true, we go to the else clause and we run this instead.
          
          So again, it's only ever running one of them and we can chain as many of these else ifs on as we want.
          
          We could have another if we want.
          
          We could do else if here and then else if again, we're not going to do that because it's just going
          
          to get messy.
          
          But the idea is there, we can chain them together if we want to.
          
          So let's run this.
          
          I'm going to change this to something like password one, two, three, four, which is 12 characters
          
          long.
          
          So hopefully we get this right here.
          
          So save it preview.
          
          And we see that that password is mighty strong.
          
          Should be mighty.
          
          Okay.
          
          And if we change this back to eight, then the first condition should fail.
          
          This should be false, but this should be true.
          
          So save it and we can see that password is long enough.
          
          If we change it to four, then it's going to go right down to the else clause and just run.
          
          This password is not long enough.
          
          All right.
          
          So there we go.
          
          That's how we use else statements and also else if statements to check multiple different conditions.