Welcome to exercise number two.
So this person is 24, but they carry a lot of debt, and so naturally their application should be rejected,
but our conditionals are not working as they should, and for some reason their application gets processed.
So let's add some break points and figure out what's going on.
OK, now we're going to launch the debugger for the conditionals class and let's step through each line
and hopefully we can find some mistakes, OK?
There's the first mistake.
So apparently their credit score here is good, but we know it shouldn't be because they're adept as
four thousand dollars.
So we can stop right here and investigate.
So if this condition is true, if debt is bigger than zero, then return good, otherwise bad.
It should be the opposite.
If their debt is higher than zero, then it should return bad, otherwise good.
By the way, this.
Is the same thing is writing this, but the conditional assignment syntax is a lot cleaner, but honestly,
you don't have to use it.
It's totally up to you if you want to use a standard NFLs to assign a value between a binary number
of choices.
Power to you if you want to use conditional assignment syntax.
The ternary operators, which can be thought of as a simplified version of the default statement, then
by all means you can do that as well.
I personally prefer using the ternary operator is when it's appropriate because it's a lot cleaner and
it's less code.
In any case, you can find the syntax in your cheat sheet.
All right, let's run the code.
All right, so relaunched the debugger, maybe there's something we missed.
Oh, this is false.
It seems like we mixed up our condition because clearly a 24 year old should be old enough.
And now do you see how useful the debugging tool is?
Because from first glance, you're not going to notice the wrongful comparison operator.
But when you can see that the output is clearly wrong, then it's going to prompt you to investigate
the matter.
And in this case, we fixed the comparison.
Hopefully now everything should be good.
So apparently this works, but to run some test cases to make sure let's do an age of 16 with adeptness
4000.
Definitely shouldn't get processed.
OK, good.
Let's do 24 years old with a zero adepts.
So this application should get processed.
But it doesn't there's something wrong with our code, and I hope you can see how important it is to
run test cases, test cases are the ultimate way to really battle test your application to make sure
that everything works the way that it should.
All right.
In any case, let's launch the debugger and see what's wrong.
At this line of code can apply is true and credit score is good, but check it out.
The if statement was programmed to process applications if they're not eligible, which doesn't make
any sense, we should only process applications where the person is eligible.
And if they have a good credit.
And I think now we're ready to run the code because we've effectively debug the application.
Let's run it one more time.
Credit score equals good because debt is no higher than zero.
The person is over 18 so they can apply.
The statement should run because the person is over 18 and has good credit score.
And so we know this line is going to run.
It's pretty amazing that we can actually visualize how the code runs and how the state of our application
changes line by line.
And so for the sake of practice, let's not forget to try the other test cases.
Credit score equals bad because that is higher than zero.
The person is under 18, so they cannot apply, the statement should run if the person is over 18 and
has good credit score, but that is not the case.
So the statement runs.
All right, last test case.
This time, the credit score is good because that isn't bigger than zero, the person is under 18,
however, so they cannot apply the system and should run if the person is over 18 and they have a good
credit score.
But that is not the case, as you can clearly see.
So we know the statement runs.
OK, there you go.
I hope you enjoy this exercise.