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

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

Challenge Task

Add an if statement that checks to see if firstExample is equal to secondExample. If it is, print out "first is equal to second". What did I do wrong

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = "hello";
if (adjective.equalsIgnoreCase("hello") 
String secondExample = "hello";
String thirdExample = "HELLO";

3 Answers

Dylan Merritt
Dylan Merritt
15,682 Points

Right now you are checking to see if String adjective is equal to "hello." You need to be checking if firstExample is equal to secondExample, and you are not doing this in the code provided. Try this:

String firstExample = "hello";
String secondExample = "Hello";

if (firstExample.equalsIgnoreCase(secondExample) {
    console.printf("first is equal to second");
}

I hope that this makes sense and that it fixes the problem! Good luck!

Craig Dennis
Craig Dennis
Treehouse Teacher

You are missing a trailing paren on your if expression.

Dylan Merritt
Dylan Merritt
15,682 Points

Honestly, this is the most cliche advice ever, but the very best thing you can do to help yourself understand is to just keep practicing. If you are interested in pursuing Java further, I highly recommend this free course on Udemy by John Purcell: https://www.udemy.com/java-tutorial/#/

It helped me to learn all of the key concepts, and it also teaches you more advanced concepts once you get a handle of the basic stuff. Other than that, truly the best advice I have to to keep making little programs like these. Complete little tasks, explore courses like John's and the ones here on Treehouse, and have fun with it!

Brandon Wash
PLUS
Brandon Wash
Courses Plus Student 1,186 Points

Thanks Dylan. I am in the introduction to see how all this makes sense. Do you have any advice or suggestions?