Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSteven Strouble
4,128 PointsWhy is -1 required?
Is it just an arbitrary int so that the methods' number of arguments match?
1 Answer
Nicolas Hampton
44,638 PointsSteven,
We're using -1 here so if it returns, we know something is wrong. To that effect, there is no point in specifically -1 except for it's a value we know the fuel level can't be. In that way, if we get output saying that the fuel level is -1, which is physically impossible, we'd instantly know something went wrong, and have an idea as to where to start looking. The default value could be set to three, but that would seem normal, except when things started to act funny, and then the problem would be much harder to find. So basically, because a -1 fuel level is SO ABSURD as to be easy to find in debugging. At the same time, it looks kind of manufactured, and differentiates itself from -3576, so we can reasonably rule out some sort of loop error. I think this might pop up as a convention a lot, the simple -1 default. That make any since?
Nicolas