Hello and welcome.
In this video I'll be introducing you to conditionals condition was r chord structures which allow you
to test if an expression or a condition returns true or not they are used to perform different actions
based on different conditions.
The common conditional statements are an if statement basically in an if statement is used to specify
a block of code that will be executed if a specified condition is true.
We also have an else statement basically that checks if the condition that is set within the if statement
is true or false.
If that is false then the code inside the else block will execute.
So the L statement will only come into effect if the condition set within the if statement returns false.
So in my console I have caught a variable here that I defined called my number and I've given it a value
of 7 and I'm using an if statement which is a conditional statement to test a condition.
So I'm checking if the variable called my name is equal to 7.
If it is the code this code here will be executed which is console the log basically means it will print
out this message.
Inside this console it will say Lucky 7 if the condition is true but looking at the condition this condition
is definitely true because a variable has a value of 7 and just check in here.
This is the condition the expression inside the F which is this.
Here is the test.
Okay so this uses the identity operator which is as equals to here to compare the value to compare if
this value here is 7 if is equal to 7 if it is it will print out that.
So I'm just going to press enter and it will print out.
Lock is 7 in the console.
So in this case the condition is true.
So no other code needs to be executed.
However you can also create a condition in which you add an else statement so that if the condition
inside the if statement is wrong then a different block of code will execute which is located inside
the else block.
So here I've got another variable.
Same called my number.
I've changed the value to 10 and here I've included two statements.
The if statement and the L statement.
So what happens is the comparison is made.
The condition is tested and the test is inside the if block inside here.
So is testing if this variable.
My number is equal to 7.
This will return false because the value is 10.
So what I have on this block of code here that says Lock is 7 will not run.
So it will not get executed because the value is wrong.
So what happens.
It will skip this block and need to execute this code because this condition inside the F is wrong.
It doesn't evaluate to.
So once a comparison has been made it all wrong the code that matches the comparison.
So in this case the code inside the comparison is made inside the F block.
So it tested the condition the condition tested false because the values 7 is not the cause of 7.
So it's not close to 10.
So the block of code here that says lock in 7 will not run.
Instead it will run this inside the console anyway you see console don't log means it's going to print
a message inside the console so 5 press enter.
He can see you saying you're not very lucky today because this condition that we tested did not evaluate
to true.
So this code here is executed instead.
So in a very simple example here to illustrate how the conditional statement works so there are order
types or conditional statement but the very basic is the F and the FS statement.
So the key thing to note here using the f an L statement is the condition to be tested or the expression
to be tested is always located in the F block.
So that's where you set the condition.
You can see he have set the condition here.
So if that condition does not evaluate to be true then the block of code inside the if statement is
skipped and the one in the else block is executed.
So in between the curly braces see opening curly braces and that's the closing collaborators is where
you write the block of code that will execute.
You can see here this is the block for the F and in the L phone you got the opening curly braces and
the closing curly braces and in between who you call the code block that executes if a condition within
the if statement or the F block is wrong.
So that's it.
I hope it makes sense.
If not please let me know.
Thank you and bye for now.