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 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,858 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: