Solution Review: Debugging 101

Solution to the "Debugging 101" exercise.

We'll cover the following

Solution

The solution needs us to trace the code to see what could be the potential values of the variables in each highlighted lines. The best approach would be to start from the first line of code and list out variables and their assigned values. However, one thing to look out for is when the scope changes. While at the same time we will be looking for the variable that we need to eventually return such that the returned value is correct.

First, trace the code to see the potential values of variables in all highlighted lines. The best approach is to start from the first line of code and list out variables and their assigned values. However, notice when the scope changes. We will look for the variable that we need to return so that the returned value is correct.

Check out the solution below.

Get hands-on with 1400+ tech skills courses.