There's one method in JavaScript that is really powerful and ideal for building a calculation, and
that's the evil function which evaluates JavaScript script code represented as a string.
So we see that we've got if we do eval two plus two, we're going to have to put a four.
We get eval, we can see that a string, we can evaluate it and so on and so on.
So we get this output one and this is the one that we're after.
We want to get that first part where we're actually evaluating the content.
And as we saw before, we essentially do have a value that we're evaluating.
So if we go into here and if we do eval and don't forget to wrap it in the brackets and we have that
value, we can see that JavaScript can calculate that out.
So even if these are strings and string values, using eval gives us a lot of power and gives us the
ability to calculate that out.
So what we want to do is we want to launch the evaluation, but only on certain keys.
We don't want every Keat that gets pressed to evaluate out on because that's not going to work properly.
So we need to make sure that we're checking to see if the correct keys and that would be any one of
the keys where we've got the equals sign or any one of these calculation keys operators that we're using
within our keyboard.
And that's where we want to apply the evaluation.
So that means that we need to search Ahrari to check to see if it's included within our array.
And there's a great example of the includes.
So array includes function in JavaScript and returns a bullying value.
So this one is ideal for what we need, where we can check to see if an array and we know we've got
that operator array that we set up earlier where we're going to check to see if our array to do a condition,
if operator includes and we're looking for the value that's contained within that text.
So the might value value.
And if it does, then that's when we can invoke our operator and we got to move this one out and then
do our evaluation of the content.
So take my calculator and use the eval and evaluate the contents that are contained within that output
stream.
So now one, two, three.
And we do plus three and we do.
Plus we see that the calculation is done.
And every time we click one of these operators, we see that we're outputting that value.
The problem comes in when we try to add two operators together and then we throw an error.
And that's because we're evaluating we've got a plus and then we're doing a minus.
So it's expecting a no numeric value there and it's not expecting to have a plus and a minus.
So that's not going to work.
And we need to apply some conditions in order to check for that to see if the last value is one of the
operators.
So we'll take care of that in the upcoming lesson.
So for now, add in the ability to check through the array using that includes and also use evaluate
in order to evaluate that string content mathematically.