1
00:00:00,360 --> 00:00:06,270
There's one method in JavaScript that is really powerful and ideal for building a calculation, and

2
00:00:06,270 --> 00:00:11,760
that's the evil function which evaluates JavaScript script code represented as a string.

3
00:00:12,030 --> 00:00:16,950
So we see that we've got if we do eval two plus two, we're going to have to put a four.

4
00:00:17,160 --> 00:00:22,710
We get eval, we can see that a string, we can evaluate it and so on and so on.

5
00:00:22,710 --> 00:00:25,710
So we get this output one and this is the one that we're after.

6
00:00:25,710 --> 00:00:30,240
We want to get that first part where we're actually evaluating the content.

7
00:00:30,450 --> 00:00:35,550
And as we saw before, we essentially do have a value that we're evaluating.

8
00:00:35,850 --> 00:00:42,960
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

9
00:00:42,960 --> 00:00:46,500
value, we can see that JavaScript can calculate that out.

10
00:00:46,710 --> 00:00:52,950
So even if these are strings and string values, using eval gives us a lot of power and gives us the

11
00:00:52,950 --> 00:00:54,420
ability to calculate that out.

12
00:00:54,450 --> 00:00:58,490
So what we want to do is we want to launch the evaluation, but only on certain keys.

13
00:00:58,500 --> 00:01:05,040
We don't want every Keat that gets pressed to evaluate out on because that's not going to work properly.

14
00:01:05,250 --> 00:01:10,200
So we need to make sure that we're checking to see if the correct keys and that would be any one of

15
00:01:10,200 --> 00:01:17,730
the keys where we've got the equals sign or any one of these calculation keys operators that we're using

16
00:01:17,730 --> 00:01:18,740
within our keyboard.

17
00:01:18,750 --> 00:01:21,070
And that's where we want to apply the evaluation.

18
00:01:21,960 --> 00:01:27,570
So that means that we need to search Ahrari to check to see if it's included within our array.

19
00:01:27,840 --> 00:01:30,510
And there's a great example of the includes.

20
00:01:30,510 --> 00:01:35,260
So array includes function in JavaScript and returns a bullying value.

21
00:01:35,460 --> 00:01:41,730
So this one is ideal for what we need, where we can check to see if an array and we know we've got

22
00:01:41,730 --> 00:01:49,680
that operator array that we set up earlier where we're going to check to see if our array to do a condition,

23
00:01:49,680 --> 00:01:57,270
if operator includes and we're looking for the value that's contained within that text.

24
00:01:57,270 --> 00:01:59,030
So the might value value.

25
00:01:59,550 --> 00:02:06,900
And if it does, then that's when we can invoke our operator and we got to move this one out and then

26
00:02:06,900 --> 00:02:09,480
do our evaluation of the content.

27
00:02:09,730 --> 00:02:17,850
So take my calculator and use the eval and evaluate the contents that are contained within that output

28
00:02:17,850 --> 00:02:18,180
stream.

29
00:02:18,540 --> 00:02:19,700
So now one, two, three.

30
00:02:20,130 --> 00:02:22,950
And we do plus three and we do.

31
00:02:22,950 --> 00:02:25,470
Plus we see that the calculation is done.

32
00:02:25,770 --> 00:02:30,370
And every time we click one of these operators, we see that we're outputting that value.

33
00:02:30,660 --> 00:02:36,810
The problem comes in when we try to add two operators together and then we throw an error.

34
00:02:37,020 --> 00:02:42,000
And that's because we're evaluating we've got a plus and then we're doing a minus.

35
00:02:42,030 --> 00:02:48,140
So it's expecting a no numeric value there and it's not expecting to have a plus and a minus.

36
00:02:48,420 --> 00:02:49,470
So that's not going to work.

37
00:02:49,470 --> 00:02:57,240
And we need to apply some conditions in order to check for that to see if the last value is one of the

38
00:02:57,240 --> 00:02:57,920
operators.

39
00:02:58,200 --> 00:03:00,180
So we'll take care of that in the upcoming lesson.

40
00:03:00,200 --> 00:03:06,960
So for now, add in the ability to check through the array using that includes and also use evaluate

41
00:03:06,960 --> 00:03:10,140
in order to evaluate that string content mathematically.
