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

Poorly worded challenge needs better description.

Here we have the code to validate that a field name contained within the fieldName String variable adheres to a set of conditions.

public class TeacherAssistant {

  public static String validatedFieldName(String fieldName) {
    // These things should be verified:
    // 1.  Member fields must start with an 'm'
    // 2.  The second letter in the field name must be uppercased to ensure camel-casing
    // NOTE:  To check if something is not equal use the != symbol. eg: 3 != 4
    if( fieldName.charAt( 0 ) != 'm' ) {
      throw new IllegalArgumentException( "fieldName must start with the letter m" );
    }
    if( !Character.isLowerCase( fieldName.charAt( 1 ) ) ) {
      throw new IllegalArgumentException( "fieldName is not camel cased" );
    }
    return fieldName;
  }
}

This code generates the error:

Bummer! Expected "mfirstname" to fail but it passed.

Which is rather confusing since there is never any mention of a variable named mfirstname anywhere in the description of the challenge so why would anyone think they need such a variable?

3 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

That is value passed in to test your method. Did you see the comments in the code?

Hi Tim Cullen, 'mfirstname' isn't a variable. what it is saying is your code doesn't throw an exception when it entered 'mfirstname', so you don't need the ! before Character.isLowerCase(fieldName.charAt(1))){.

Yes I did. The code wrote to complete this challenge implements precisely what the comments describe. The problem here is deeper than that. The problem appears to be that the compiler is looking to do something with a variable called 'mfirstname' as we can see by the error message generated:

Bummer! Expected "mfirstname" to fail but it passed.

Which by the way is not following the Camel Casing convention. The crux of the problem here is that neither the challenge description, the comments in the code, or the code I implemented reference a variable named 'mfirstname'. This tells us that there is a disconnect between what the compiler is expecting and what the person who wrote the comments is expecting.