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 Censoring Words - Looping Until the Value Passes

Lujain Alzunaid
PLUS
Lujain Alzunaid
Courses Plus Student 316 Points

I'm stuck on the 2nd objective of the Code Challenge!

I'm trying to print out the punchline for a code but it won't go through. how can I stop the loop and let it print out the punchline? the objective says "Print out the punchline using the who variable"

console.printf("Knock Knock.\n"); String who; Boolean bananaYes; // Person B asks and Person A's response is stored in the do { who = console.readLine("Who's there? "); bananaYes = (who.equalsIgnoreCase("banana")|| who.equalsIgnoreCase("Orange")); if (bananaYes) { // Person B responds: console.printf("%s who?\n", who); } }while (bananaYes)

console.printf("%s you glad I didn't say banana again",who);

1 Answer

Allan Clark
Allan Clark
10,810 Points
bananaYes = (who.equalsIgnoreCase("banana")|| who.equalsIgnoreCase("Orange"));

Here is your bug. This variable should only be checking if who is equal to "banana". Checking for both will keep you inside the do-while loop as long as you get banana or orange, you only want to stay inside the loop while who is banana.