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 trialNAJEEBULLAH KHAN
2,967 Pointsit keeps on saying task 1 not passing even though i only made a public void int drive;
why
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 int drive()
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! The reason it is saying that "Task 1 is no longer passing" is because you've introduced a syntax error in your code which results in a compiler error. The code can no longer be compiled at this point. A method may only have one return type. But your method has two return types. You've said void int
. Both void
and int
are data types. The void
is a special data type which means essentially "nothing". At this point, you're trying to tell the method that it will return both an int and nothing at the same time.
The challenge requests a return type of void
, so you can safely remove the int
. Also, your function is missing the open and closed curly braces which will also cause a compiler error. Lastly, the challenge is asking you to increment the number of laps driven inside the body of the method, but currently, your method has no body.
public void drive() {
lapsDriven++;
}
This creates a method named drive
that returns nothing. In the body of the method, we increment the number of laps driven by one using the shorthand discussed in the video.
Hope this helps!