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 trialDinu Comendant
6,049 PointsExercise error, or I don't fully understand something here?
The first task asks you to use -= and +=, so I did, and it counted, but then I've been looking at my formula and it didn't make sense. So I tried to write the formula differently, for example:
lapsDriven-=barCount;
lapsDriven+=barCount;
//
barCount-=lapsDriven;
lapsDriven+=barCount;
and so on, tried every method and the exercise will always tell me that it's correct, but I get the feeling that something is wrong and it doesn't make sense
1 Answer
<noob />
17,062 PointsHi, you understand it wrong, although this question is a little confusing but here is what u need to do:
public void drive(int laps) { lapsDriven += laps; barCount -= laps; }
they ask u to add a parameter to the method that represent the number of laps that a goKart user as drove. for example hypotatically letβs that laps = 3 then u drove 3 laps and then barCount decrement laps which holds 3 to know how many energy bars u wasted. laps is just a placeholder for the number of laps u drove, it is used to let the user to decide how many laps he will drive.