Welcome back everybody.
All right.
So let's go ahead and let's go and add something to the if statement so if I type in any kind of word
here and I change the text it all works just same as the last of Toral.
Now you can add something to the statement called an L statement which is something you just say.
Else.
Now of course an else statement needs to curly braces.
And what I mean to do here is I'm going to copy this over and paste it in here instead of making change
text variable to something.
I'm just going to make it make two strings saying else statement fired up like that k and all it's all
going to say is that when I do this here for example if I type in word f here it's going to work because
cool numbers equal one.
But if I change just two instead of the if statement is going to go to the else and let's just walk
through.
So is if the if statement is equal to 1 then this is going to work.
Elle's means that if cool number is equal to any other number other than 1 it will go ahead and put
this in here so I can type in whatever I want but it's going to say L statement as far as always going
to say that if cool number is not equal to what it could be equal to a thousand it can be equal to negative
56.
It doesn't matter what what cool number is equal to if it's not equal to 1.
The statements get to fire.
Now the other thing that we need to check up here is that you'll see that there are two change text
variables.
And why is why can this work.
So you'll see that there is a change text variable here and then a change takes a variable here.
Now in a couple of previous tutorials I did tell you that you can't make a variable equal to the same
name.
And I did say that but it changes a little bit here.
If I were to add a number another variable called Cool number it would throw an exception because the
computer doesn't necessarily know which cue which variable to look at.
So it could be cool number or cool number which is the same.
It gets confused.
However when you set up a variable within these curly brackets this this works is something called variable
scope meaning that change takes variable is only usable within this if statement.
I can't use it outside of this if statement at all.
Right.
And again just change text variable is only usable within the else statement.
It's not usable outside that.
So if I Hopoate outside the IF and then by the way this is the entire If statement here.
This is the if statement and this is the statement but the whole thing works like this.
OK.
And.
And so if you think about it here this is more function we can you know do some stuff in here but if
I type in change text variable k you see that it does kind of work but it won't it won't.
You can see that there's a whole bunch of warnings here that the text changes.
But again you know in this editor it doesn't it only looks for the strings within within the document
and doesn't look for it inside scope.
You need to go to something like Visual Studio or next quarter of stuff like that.
OK.
But you can see there's four warnings here and because this variable is essentially undefined meaning
that it doesn't even know it exists right.
And again remember you have to declare the variable which is what I've done here.
In order for the computer to see if that variable is actually usable.
So again I can get away with this and we can I can get away with actually having to change text variable
in as many if statements is what I could have a 100 of these if I really wanted to.
Now the major question is is should you change the variable within the if any else statement.
So for example here you can see that it says there's two changes text variables that can get kind of
confusing.
Some people do change it up.
It's up to you whether you want to do that or not.
Personally I tend to not use these local variables as much as I can.
One thing that javascript is actually really good at is referencing virtual variables across scope in
other programming languages.
It's not necessarily that easy.
All right so for the most part that is how an else statement works.
All right I'll see you guys in next tutorial.