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 trial

Java Java Objects (Retired) Creating the MVP Remaining Characters

Michelle Bramlett
Michelle Bramlett
1,253 Points

Returning 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?

Tweet.java
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

Check 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();
    }

}

I 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!

Michelle Bramlett
Michelle Bramlett
1,253 Points

Thank you!! Appreciate you taking the time:)

My pleasure, Glad I could be helpful. :)