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 trialSteve Wofford
2,485 PointsTask 1 works, but then task 2 says task 1 doesn't work right after.
When i start the first tasks. it ask me to give a private int lapDriven. I did just that and it works. Then when i get to task 2, and i try putting in the next increments, the challenge says task 1 is no longer passing. How? Every time i go back to task 1, it works and goes to task 2 it wants me to go back to task one. Can someone please help me understand?
class GoKart {
public static final int MAX_BARS = 8;
private String color;
private int barCount;
private int lapsDriven;
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;
}
public void drive(int laps) {
if(laps > barCount){
throw new IllegalArgumentException();
} else {
lapsDriven += laps;
barCount -= laps;
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Generally speaking, when it says that a previous task is no longer working, it's because you've introduced a syntax error into your code that wasn't present before. There can be other causes for this, but this is the primary reason you would receive this message.
Just glancing at your code that's posted here, I can tell you that you're missing no less than 2 closed curly braces/curly brackets. Check the last drive
method. Each open curly brace/curly bracket should have a matching closed one.
Hope this helps, but let me know if you're still stuck!
Jacob Klug
469 PointsDid craig teach us about throw new or else yet because I dont recover learning about any of that especially the throw new code
Steve Wofford
2,485 PointsSteve Wofford
2,485 PointsIve added the 2 brackets and still tells me the first task is no longer passing. The reason i know it isn't a syntax error is because when i check my work on task 2 even before adding anymore code, it stills says task 1 is no longer working. How does it not work when it just worked on task 1?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherCan you please post the code you're currently trying? I'd like to take a better look at it after you've added the closed braces/brackets.
Steve Wofford
2,485 PointsSteve Wofford
2,485 PointsIve figured something out by some of the other forums. I appreciate the help!