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 trialMichelle Bramlett
1,253 PointsReturning Characters Challenge 2
Being asked to "Add a new method that returns the remaining characters available, based on the length of what is currently stored in mText." Have reviewed community help- as far as I can tell my code should pass? Any insight as to why it is not?
public class Tweet {
public static final int MAX_CHAR = 140;
private String mText;
public Tweet(String text) {
mText = text;
}
public String getText() {
return mText;
public int remainingChar() {
return MAX_CHAR - mText.length();
}
}
}
2 Answers
Brian Bochicchio
19,978 PointsCheck out these function declarations...
...
public String getText() {
return mText;
public int remainingChar() {
return MAX_CHAR - mText.length();
}
}
}
You defined remainingChar before closing getText.
public String getText() {
return mText;
}
public int remainingChar() {
return MAX_CHAR - mText.length();
}
}
Michelle Bramlett
1,253 PointsThank you!! Appreciate you taking the time:)
Brian Bochicchio
19,978 PointsMy pleasure, Glad I could be helpful. :)
Brian Bochicchio
19,978 PointsBrian Bochicchio
19,978 PointsI clicked submit too fast so that may have been confusing.
In the first code snip, you declare the remainingChar() function before you close the getText() function. Which should be the source of the "illegal start of expression" in the debugger.
In the second, the functions are separated (declared) correctly. So the code passes the challenge.
Happy Learning!