OK, welcome back.
Now we're on lesson 10, we're in to learn about the ternary operator.
This is extremely similar to IF and L's short version.
OK, so this is shorthand expression that's going to be the same as an IF and else.
What's really nice is how concise the language is.
All you're basically going to do is do the first condition that you're going to check for, just the
same as if you did.
If fruit is mango return that ls return that this is going to save you having to say return, save you
having to say else.
It's just going to put it all into this question mark you've really written out as a question.
Is fruit the same as mango.
Hmm.
If true it'll return this value and if false it will return the value after the colon.
OK, so it uses a question mark after the conditional statement in a colon after the first return if
the condition is met.
So let's take a look at that in code.
All right.
So why don't we start with this example right here and let's bring this over to us in 10.
All right.
So we have Phyto is a we'll be happy soon.
Let's make him happy again.
Phyto is a happy dog.
OK, so how would we convert this into a ternary operation so that we can simplify this?
Well, all we would have to do is take the conditional expression right here
and then we just put a question mark.
In fact, what we could do is just consider on this whole thing so we can use return values instead.
Colin.
OK.
I'm thinking we're probably missing some.
Oh, we're missing the end parentheses on the council blog.
All right, so all of that fit right there.
And to simplify this, just so we can read this a little bit cleaner.
Happy, and we'll just say happy.
To.
OK,
so it's really this simple.
OK, this is the same as this we would happy, huh?
Is it true?
Yes.
Happy if not not happy.
Let's change this to sad and you'll see them both change.
Not happy to back to happy.
Very good.
OK, so that's the ternary operator,
ternary operator and it basically replaces simple if else statements and really cleans it up, as you
can tell.
So here's where your comparison is going to be.
Here's what your true return is going to be, and here's what your false return is going to be.
OK, and that's it for the ternary operator.