It's time to diving into if nails is statement.
And to make this topic more interesting, let's build a very, very small application where we have
an age and based on a number, I want to return to the console.
If the number makes the person an adult or not yet, or not an adult, and the number can be 18 for
example.
So how the F analysis statements work, let's first create a variable.
These variable will call as age, and the age of a here will be 18 years old or sorry, 20 years old,
ten years old.
And then inside of my code, I want to make sure if the.
Age is greater than 18.
It's an adult.
And if is lower than 18, it's not yet an adult.
So let's make that happen.
A very simple if and else statement.
So I will start with the F and then inside of parentheses I need to add my condition.
What is my condition?
Age if I can type age.
Age should be if age is greater or equal than 18, what is happening?
What should I return?
And then I open and close the curly braces and then I need to return my statement.
So if the condition is true, what should I return?
I return to the console.log.
For example, you are an adult.
You.
Are un.
Adult OC simple like that.
If the age is greater or equal to 18, you are an adult.
And then I can keep adding more statements over here.
Or I can just leave these curly braces and go to the second part.
The second part is the ls.
I can use ls or else if if I had more options, for example, or if you are between 13 and 19, you
are a teenage so young teenage adult.
More options.
I will use the elseif and else even else if.
But because I only have two.
I don't need to use the elseif.
I'm going to use just the else.
So the else will be what the else will be returned to the console dot log.
The message you are.
You are not yet un.
Yet un.
Adult.
Period.
You are not yet an adult.
Simple.
Like this.
Yeah.
So the first statement, the first condition is equal or greater than 18.
If that is not, that means it falls to the second one.
So the if analysis statement always checks from the top to the bottom.
If these one is true.
It returns the statement if is false.
It will jump to the next.
Section of my F and else it will check the condition in my case.
Over here, the LS doesn't have a condition.
So is anything else?
Yeah.
Anything else?
That's not the first one.
So if you want to try that.
And see if that works.
Let's try.
Let me save the config.
And they says you want an adult because the number is 18.
How about the number is 20?
How about 18?
18 is an adult.
Why is an adult?
Because it's greater than and equal to if I do.
17.
You are not yet an adult.
If I do 89 years old, you definitely an adult.
So if statements so cool, so easy to work with.
And again, if if you check any any any application out there, they will have at least one if an LC
statement.