Okay.
So, I hope you successfully did that.
And so, let's try to solve it now together.
Or actually, let me show you my solution
so that you can see how it compares with yours.
And as always, you can also find my solution
in the final folder in the GitHub repository.
Okay?
Now actually, let's start with the bill variable
which I'm gonna set to 275
which is here the first test value.
And now, the tip
and let's calculate it using the ternary operator.
So, let's implement this rule,
which is, if the value is between 50 and 300,
then the tip should be 15% of the bill value.
So, that means that bill must be less or equal 300,
and at the same time,
bill must be greater or equal than 50, right?
And again, that's what it means for the bill value
to be between 300 and 50.
It's gonna be less or equal 300,
and at the same time, greater or equal than 50.
So, 40 for example, is of course less than 300
but it's also less than 50.
And so, this part here will then be false.
And so, this entire expression here,
which is than true and false will be false as well, right?
So, in this case, the tip here will be the bill value
times 15%,
which as I explained here,
all we need to do is to multiply it by 15 divided by 100,
so that 0.15.
And else it's 20%.
So, bill times 0.2.
Give it a save, and that's actually it.
So, that's number one.
And now, as number two,
let's lock this string to the console
as is requested here in number two.
So, let's actually grab this template here.
So, then we just have to replace the values.
And so, since we're building a string,
we are again relying on the template literal.
So, here we're gonna put the bill value.
Here we're gonna put the tip.
And we're missing the curly braces.
And here the total value is gonna be the bill plus the tip.
So, we can, as you already know, write an expression here
using this operator,
so the plus operator.
And that's actually it.
So, let's try it
and with this bill value,
the output should actually be exactly
like it's written up there.
And it is.
So, 275, the tip is 41.25,
so just like here.
And the total value is 316.25.
Great.
And just to understand this one,
so this condition a little bit better,
let's just take this one and paste it here into the console.
And so, we see that this one is true.
And of course that's because 275 is less than 300
and more than 50.
So, it is between this range.
And therefore, this part of the ternary operator here
will be executed and become the result
of this operator essentially, right?
So, the result of this operator
will be bill times 0.15
and that's the value that will then be assigned
to the tip variable, okay?
Now, let's try another one.
So, 40,
and now the tip was 8.
Let's try this one here again.
And now the condition is false.
So, remember that here in the console
we have access to all the variables
that we have declared here.
So, if I write bill now, you will see that it's actually 40.
So, bill is obviously below 300, but it's also below 50.
So, this part is false,
and true and false gives false.
And so, in this case,
the value that's gonna be assigned to tip is 40 times 0.2,
and that's exactly 8.
So, it's what we see here.
Okay. And now just for the sake of completion,
let's do the last one as well.
And yeah, this should have worked as well
because now this one is false again.
I mean, that's because this time 430 is above 300
and so, 86 should be 430 times 0.2.
Let's quickly check that 0.2.
And that's right.
That's the 86 that we have up here.
Great.
So, hopefully you did this.
And once more, if you did it a little bit differently,
that's not a problem at all.
I just hope that you made it work.
Okay.
And actually this concludes the coding part of this section.
There's just one more lecture left,
which is gonna be a deeper dive into JavaScript versions,
especially into ES5 and ES6.
So, it's gonna be an interesting one.
And yeah, I'm waiting for you there.