Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype String Equality

Cant figure out this question

I cant figure out this question

// I have imported a java.io.Console for you, it is named console. 
if (firstExample.equalsIgnoreCase("secondExample")){
    console.printf("first is equal to second  \n\n");
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";

1 Answer

Jason Anders
Jason Anders
Treehouse Moderator 145,704 Points

Hey Chad,

There are actually 3 errors here:

  1. secondExample cannot be in quotation marks. You are comparing the values inside the variables. Once you put quotes around it, you turn it into a string. So, it's comparing the first value to the literal "secondExample".
  2. You have an opening curly instead of a closing one for the end of the if statement.
  3. And very important... The if statement needs to come after the variable declarations. At the top, like you have now, the if statement has no idea the firstExample or the secondExample variable even exist, so you would get a compiler error. In Java, and almost all languages, variables need to be declared before they can be used.

So, give it another go with these in mind. Once those are corrected, the code will pass. :)

Keep Coding! :dizzy: