1
00:00:00,390 --> 00:00:01,920
Welcome to exercise number two.

2
00:00:03,840 --> 00:00:10,200
So this person is 24, but they carry a lot of debt, and so naturally their application should be rejected,

3
00:00:10,210 --> 00:00:15,890
but our conditionals are not working as they should, and for some reason their application gets processed.

4
00:00:16,620 --> 00:00:19,200
So let's add some break points and figure out what's going on.

5
00:00:28,390 --> 00:00:34,270
OK, now we're going to launch the debugger for the conditionals class and let's step through each line

6
00:00:34,270 --> 00:00:37,150
and hopefully we can find some mistakes, OK?

7
00:00:37,180 --> 00:00:38,220
There's the first mistake.

8
00:00:38,230 --> 00:00:42,850
So apparently their credit score here is good, but we know it shouldn't be because they're adept as

9
00:00:42,850 --> 00:00:44,260
four thousand dollars.

10
00:00:45,190 --> 00:00:48,340
So we can stop right here and investigate.

11
00:00:49,250 --> 00:00:54,560
So if this condition is true, if debt is bigger than zero, then return good, otherwise bad.

12
00:00:55,460 --> 00:00:56,510
It should be the opposite.

13
00:00:56,880 --> 00:01:00,860
If their debt is higher than zero, then it should return bad, otherwise good.

14
00:01:06,030 --> 00:01:07,500
By the way, this.

15
00:01:09,780 --> 00:01:16,380
Is the same thing is writing this, but the conditional assignment syntax is a lot cleaner, but honestly,

16
00:01:16,380 --> 00:01:17,560
you don't have to use it.

17
00:01:17,580 --> 00:01:23,130
It's totally up to you if you want to use a standard NFLs to assign a value between a binary number

18
00:01:23,130 --> 00:01:23,910
of choices.

19
00:01:23,910 --> 00:01:27,660
Power to you if you want to use conditional assignment syntax.

20
00:01:27,660 --> 00:01:32,760
The ternary operators, which can be thought of as a simplified version of the default statement, then

21
00:01:32,760 --> 00:01:34,320
by all means you can do that as well.

22
00:01:34,530 --> 00:01:39,210
I personally prefer using the ternary operator is when it's appropriate because it's a lot cleaner and

23
00:01:39,210 --> 00:01:39,990
it's less code.

24
00:01:40,650 --> 00:01:43,230
In any case, you can find the syntax in your cheat sheet.

25
00:01:44,040 --> 00:01:45,300
All right, let's run the code.

26
00:01:55,630 --> 00:01:58,720
All right, so relaunched the debugger, maybe there's something we missed.

27
00:02:07,580 --> 00:02:08,900
Oh, this is false.

28
00:02:09,320 --> 00:02:13,790
It seems like we mixed up our condition because clearly a 24 year old should be old enough.

29
00:02:14,540 --> 00:02:17,150
And now do you see how useful the debugging tool is?

30
00:02:17,420 --> 00:02:21,560
Because from first glance, you're not going to notice the wrongful comparison operator.

31
00:02:21,770 --> 00:02:26,630
But when you can see that the output is clearly wrong, then it's going to prompt you to investigate

32
00:02:26,630 --> 00:02:27,140
the matter.

33
00:02:27,380 --> 00:02:29,720
And in this case, we fixed the comparison.

34
00:02:31,600 --> 00:02:33,280
Hopefully now everything should be good.

35
00:02:43,280 --> 00:02:49,160
So apparently this works, but to run some test cases to make sure let's do an age of 16 with adeptness

36
00:02:49,160 --> 00:02:49,940
4000.

37
00:02:52,880 --> 00:02:54,620
Definitely shouldn't get processed.

38
00:02:59,920 --> 00:03:00,490
OK, good.

39
00:03:01,080 --> 00:03:03,670
Let's do 24 years old with a zero adepts.

40
00:03:06,920 --> 00:03:08,990
So this application should get processed.

41
00:03:12,260 --> 00:03:17,930
But it doesn't there's something wrong with our code, and I hope you can see how important it is to

42
00:03:17,930 --> 00:03:23,210
run test cases, test cases are the ultimate way to really battle test your application to make sure

43
00:03:23,210 --> 00:03:25,010
that everything works the way that it should.

44
00:03:25,730 --> 00:03:26,200
All right.

45
00:03:26,210 --> 00:03:29,090
In any case, let's launch the debugger and see what's wrong.

46
00:03:36,020 --> 00:03:40,790
At this line of code can apply is true and credit score is good, but check it out.

47
00:03:41,030 --> 00:03:47,120
The if statement was programmed to process applications if they're not eligible, which doesn't make

48
00:03:47,120 --> 00:03:51,530
any sense, we should only process applications where the person is eligible.

49
00:03:53,460 --> 00:03:55,650
And if they have a good credit.

50
00:03:56,970 --> 00:04:01,230
And I think now we're ready to run the code because we've effectively debug the application.

51
00:04:13,650 --> 00:04:14,750
Let's run it one more time.

52
00:04:21,589 --> 00:04:24,470
Credit score equals good because debt is no higher than zero.

53
00:04:26,640 --> 00:04:29,040
The person is over 18 so they can apply.

54
00:04:31,460 --> 00:04:35,810
The statement should run because the person is over 18 and has good credit score.

55
00:04:37,110 --> 00:04:39,030
And so we know this line is going to run.

56
00:04:39,780 --> 00:04:45,450
It's pretty amazing that we can actually visualize how the code runs and how the state of our application

57
00:04:45,450 --> 00:04:46,860
changes line by line.

58
00:04:49,080 --> 00:04:53,010
And so for the sake of practice, let's not forget to try the other test cases.

59
00:05:08,450 --> 00:05:11,330
Credit score equals bad because that is higher than zero.

60
00:05:12,710 --> 00:05:18,170
The person is under 18, so they cannot apply, the statement should run if the person is over 18 and

61
00:05:18,170 --> 00:05:20,300
has good credit score, but that is not the case.

62
00:05:24,460 --> 00:05:25,990
So the statement runs.

63
00:05:30,710 --> 00:05:32,360
All right, last test case.

64
00:05:39,190 --> 00:05:44,620
This time, the credit score is good because that isn't bigger than zero, the person is under 18,

65
00:05:44,620 --> 00:05:50,470
however, so they cannot apply the system and should run if the person is over 18 and they have a good

66
00:05:50,470 --> 00:05:51,090
credit score.

67
00:05:51,220 --> 00:05:53,830
But that is not the case, as you can clearly see.

68
00:05:54,070 --> 00:05:56,170
So we know the statement runs.

69
00:05:59,780 --> 00:06:00,750
OK, there you go.

70
00:06:00,770 --> 00:06:02,630
I hope you enjoy this exercise.

