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

Wesley McElwee
Wesley McElwee
4,250 Points

Code challenge giving error on what I think is correct code.

I'm on task 2 of this challenge and I'm testing the equalsIgnoreCase. My code is shown below.

It's returning the error saying "Make sure you're using equalsIgnoreCase on the firstExample and console.printf

Not sure what I'm doing wrong. I also tried swapping the firstExample and thirdExample in the IF statement but same results.

Equality.java
// I have imported a java.io.Console for you, it is named console. 
String firstExample = "hello";
String secondExample = "hello";
String thirdExample = "HELLO";
if(firstExample.equalsIgnoreCase(thirdExample)) {
 console.printf("first and third are the same ignoring case"); 
}

4 Answers

foxtails
foxtails
3,655 Points

p.s. don't delete the first task code just add the next task as it asks in the question for both codes. This gave me a headache too. You are doing great.

The steps you should do:

First, you need to do the first task, which is: if (firstExample.equals(secondExample)) { console.printf("First is equal to second"); }

Then, you do what you just did for the second task, and everything should be OK.

Hope this helps!!!!

Wesley McElwee
Wesley McElwee
4,250 Points

I feel like that is what I did but I'll try again. Thanks for the replies.

UPDATE: Ah, I see what you mean now. I misread the question and your replies. The second step needs to have BOTH if statements in there.

Thanks so much :)

foxtails
foxtails
3,655 Points

You are welcome. Took me a day to realize, what was wrong, when I did this. So you are doing just great!