Tip:
Highlight text to annotate it
X
What's going on everybody! My
name is Jack Jenkins and this is Academy
of One. Today we're gonna be talking about
if statements. In this video
I'm gonna be talking about the if
statements. Then, I'm gonna be throwing in the
else. Then I'm gonna be talking about the
if else statement. [Music]
[Music]
[Music]
So heres how the if statement looks. If
and then you have your expression. Then the statement
will run only if the expression
is true. Here's an example
if x is equal to
3 and if x is less than
6 then console.log x is
less than 6. Of course, x
which equals 3 is less than 6
so it will print out this x is less than 3.
Or x is less than 6.
[Music]
[Music]
[Music]. So, we have
a standard if statement and then we're aloud to throw in
an else statement. So let's say we have
the if statement and the if statements expression is wrong.
Then it will run the else statement.
Instead. So let's say we have the variable
x is equal to 9.
and we have the if statement x is less than
6. We'll this is false
so instead of running the block directly below the
if statement. We'll run the block in the else statement.
So what will be printed out would be
x is greater than 9.
Which is isn't. It should be x is greater than 6 but I
made a typo. [Music]
[Music]
[Music]
So now that we got the else and the
if statement. It's time for the else if statement.
The elf, the else statement allows us to
add another expression. So if
expression is wrong then it will check to see if the else
if statement is right. And if that's
wrong then it will run the else statement. So let's
have x equal to 2. We'll
have the first if statement, x = 1.
Which it's not. So we'll go to the else if
statement. If x is equal to 2, which
it is, then we'll do console.log x is
2. Which it is. So what will print out is
x is equal to 2. Now it does
check if the else statement is true even though we already
did the else if statement. So it will check to see the else statement.
And that will be wrong. So what 100 percent be
true will be the else if statement. And
thats what will get run. That's it for today's
video on if statements. Can't wait til
next time for when we're going to be talking about for
loops. Alright, so here's
time for the plugs. Go ahead and subscribe to us
on youtube. Go ahead and donate, and please donate.
Go ahead and email me at jack@academyofone.org
for when I'm gonna be answering you're guyses
questions. You can go ahead and go
to academyofone.org.
And go ahead and follow us on twitter, cause I'm
gonna be starting to tweet alot more. Have a
great day everyone.
[Music]
[Music]
[Music]