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 Comparing Characters

Code for Comparing Chars seems to be fine (no syntax errors), but not working; can't figure out what I'm doing wrong!

Code doesn't come up with any syntax errors, but I'm still not passing the challenge; am I missing an essential line or something?

ConferenceRegistrationAssistant.java
public class ConferenceRegistrationAssistant {
  int line = 0;
  public int getLineFor(String lastName) {
    /* If the last name is between A thru M send them to line 1
       Otherwise send them to line 2 */
   if  (lastName.indexOf(0)<= 'M'){
     line = 1; 
   } else line = 2;
    return line;
  }

}

2 Answers

You aren't getting syntax errors, but are you getting any other kind of errors? If so, what does it say? Also, is this all of the code for this project so far? If there is more, it might be helpful to post it.

Those questions are just for future reference because I do see an obvious issue (hint: it is a syntax error):

else line = 2;

No, no other kinds of errors (which is the part of the problem - hard to tell what I'm doing wrong in that case), and this is all of the code I have so far.

I'm going to investigate that line you pointed out, thanks!

If you need extra help, a general if-else block looks like this:

if (boolean logic) {
    //do something.
} else {
    //do something else
}

or

if (boolean logic) {
    //do something.
} else (boolean logic) {
    //do something else
}

Generally you would only do it the second way for if-elseif blocks, but it works either way.

Ha, thanks - I figured I was missing the { } braces for the else block and fixed it!