1
00:00:00,150 --> 00:00:00,900
Welcome back.

2
00:00:00,930 --> 00:00:06,210
How's it going in this lesson, we are going to fix the problem that we experienced in the last lesson

3
00:00:06,390 --> 00:00:13,200
so we saw that evaluate is gives us the ability to evaluate the string and allows us to do the calculations

4
00:00:13,200 --> 00:00:17,820
so we get the string value that's contained within our output screen and then we can apply some type

5
00:00:17,820 --> 00:00:18,990
of evaluation to it.

6
00:00:19,380 --> 00:00:22,740
The problem came when we tried to apply different operators.

7
00:00:22,890 --> 00:00:24,030
We see we throw an error.

8
00:00:24,300 --> 00:00:30,930
So that means that we need to look and check to see if the lost value in our string is one of the operators.

9
00:00:31,140 --> 00:00:38,700
And if it is, then we can't evaluate or we need to remove out that current string value and before

10
00:00:38,700 --> 00:00:42,120
we do anything or we can evaluate it, but we need to remove that out.

11
00:00:42,450 --> 00:00:45,300
And the way that we can do that is using substring.

12
00:00:45,510 --> 00:00:51,180
So substring method returns the part of the string between the start and the end indices or the end

13
00:00:51,180 --> 00:00:52,100
of the string.

14
00:00:52,380 --> 00:00:58,530
And this is ideal because what we want to do is we want to return back the end of the string so we can

15
00:00:58,530 --> 00:01:01,950
see where we've got a starting position for the substring.

16
00:01:01,950 --> 00:01:08,050
And when it's outputting here, when it's using the string called Mozilla, it's outputting ause so

17
00:01:08,070 --> 00:01:14,310
starting position is one and it's returning back all the way to two, but not including three.

18
00:01:14,490 --> 00:01:18,420
And then here it's starting at two and it's doesn't have an end.

19
00:01:18,570 --> 00:01:22,660
So the substring just continues till the end of the string value.

20
00:01:23,040 --> 00:01:27,910
So what we need to do from all of this is we need to simply pull out that last character.

21
00:01:28,170 --> 00:01:33,900
So going back into our script, let's refresh and we'll minimize this back down.

22
00:01:34,200 --> 00:01:41,990
Open up our editor and let's get our last string value because we want to check to see if it's zero.

23
00:01:42,420 --> 00:01:47,430
So checking to see if and first of all, let's create a variable.

24
00:01:47,430 --> 00:01:54,210
We can just call it last character and taking the my calculation string so that remember, this is that

25
00:01:54,210 --> 00:02:01,950
output, the entire text of that output screen and using substring and there's a formula here that's

26
00:02:01,950 --> 00:02:02,560
being shown.

27
00:02:02,850 --> 00:02:08,700
So what we want to do is we want to return back only the last character and the way that we can do that.

28
00:02:08,700 --> 00:02:10,590
And we saw that as well.

29
00:02:10,590 --> 00:02:17,980
Within that example at the Mozilla Developer Network where we take the Mekaal and because we've using

30
00:02:17,980 --> 00:02:22,350
the string methods, we can get the length of what's available in the Michael.

31
00:02:22,560 --> 00:02:28,020
So we know how many characters are in the string and if we subtract one, that we get the index value

32
00:02:28,020 --> 00:02:29,510
of the last character.

33
00:02:29,790 --> 00:02:30,760
So let's see what happens.

34
00:02:31,200 --> 00:02:35,340
So we've got our last character and we want to output our last character.

35
00:02:35,790 --> 00:02:39,350
So we see that's outputting our last character.

36
00:02:39,370 --> 00:02:42,810
So whatever our last character is, we see it's being output there.

37
00:02:43,120 --> 00:02:49,290
So next, what we need to do is check before we evaluate, check to see what the last character is.

38
00:02:49,500 --> 00:02:53,130
And that means another condition within this condition.

39
00:02:53,130 --> 00:02:56,790
Checking to see if the my operator.

40
00:02:56,820 --> 00:03:05,940
So just as before, just as above includes and will check to see if it includes the last character and

41
00:03:05,940 --> 00:03:12,480
if that last characters there, then that means that we need to abort and we can't evaluate that string.

42
00:03:12,480 --> 00:03:14,420
Otherwise we're free to evaluate.

43
00:03:14,430 --> 00:03:21,570
And if it is there and if it is the last character that what we want to do is take my cowl and we want

44
00:03:21,570 --> 00:03:24,320
to subtract that last character out.

45
00:03:24,630 --> 00:03:30,360
So that means that we equal Michael to Michael and using substring once again.

46
00:03:30,510 --> 00:03:32,550
And this time we're going to do the opposite.

47
00:03:32,550 --> 00:03:40,980
We're going to get the string starting at zero position, taking the Michael length minus one.

48
00:03:41,550 --> 00:03:44,470
So that will effectively remove that last character.

49
00:03:44,850 --> 00:03:46,660
So I think we're ready to try that out.

50
00:03:46,680 --> 00:03:50,620
So before we had the error where we had different operators at the end.

51
00:03:51,000 --> 00:03:57,150
So now when I've got a plus operator, I can do a minus operator multiplication and they're not interfering.

52
00:03:57,150 --> 00:04:01,650
I can switch them and go in between them and it's not throwing any errors.

53
00:04:01,830 --> 00:04:03,530
So this is actually exactly what we wanted.

54
00:04:03,780 --> 00:04:07,450
And next, we need to still evaluate out and do the equals sign.

55
00:04:07,710 --> 00:04:12,230
So that's another thing that is still missing and we need to evaluate the equal sign.

56
00:04:12,510 --> 00:04:16,120
So that's coming up in the next lesson where we're going to do the evaluation for the equals sign.

57
00:04:16,230 --> 00:04:20,010
So go ahead and add this in practice Substring and added into your project.
