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 trialJustyn Jackere
561 PointsCan't seem to figure out what I've done wrong regarding the shorthand way to increment the int variable lapsDriven.
Hi everyone,
After combing through the newly created int variable "lapsDriven", as well as the method "drive", I can't figure out why I keep getting this code challenge wrong. Could it be that I haven't assigned the "lapsDriven" variable the value of 1?
Thank you in advance for your help.
class GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
public GoKart(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public void charge() {
barCount = MAX_BARS;
}
public boolean isBatteryEmpty() {
return barCount == 0;
}
public boolean isFullyCharged() {
return MAX_BARS == barCount;
}
private int lapsDriven;
public void drive() {
int lapsDriven += 1;
}
}
1 Answer
pet
10,908 PointsWhat Craig is referring to as short hand is
++
not
+=
good job though got stuck there too. :)
Justyn Jackere
561 PointsJustyn Jackere
561 PointsPet,
Thank you so much for your quick response. I tried the ++ and it worked. I actually forgot about it after Craig's video lesson had ended lol.
pet
10,908 Pointspet
10,908 PointsNo problem Justyn. :)