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 - Using Logical ORs

Richard andreasen
Richard andreasen
4,591 Points

or statement isn't registering

the || function isn't registering in workspace it's highlighted red and when I enter jerk after compiling it and saving it it'll continue down the loop instead of exiting.

String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")) { console.printf("That language is not allowed. Exiting \n\n"); System.exit(0); }

Hi Richard. It looks OK to me. Could you share a snapshot of your workspace here, please? (the option is at the top right corner of your workspace next to the fork option). Thanks

Thanks. It looks like you've added to the code since so it will be difficult to answer your question. Is it working now? The code as it is now in the workspace you shared runs fine on my side. The OR operator (||) is supposed to be in red, so don't worry about that. Is it possible you might have forgotten to save the file before running it (it happened to me many times)?

Richard andreasen
Richard andreasen
4,591 Points

yeah i figured that i might not of been saved but it was and i just added the other line it doesn't work still i'll try to restart browser and comp who know it might work

You mean you uncommented that line

// if (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")) {

and commented out those 3?

if (noun.equalsIgnoreCase("dork") ||
            noun.equalsIgnoreCase("jerk") ||
            noun.equalsIgnoreCase("nerd")) {

If so, it works fine on my side.

OK. You're welcome! I'm glad it's all working fine in the end :)

1 Answer

Richard andreasen
Richard andreasen
4,591 Points

it works now and i only added the other line of code to follow along with the video and the reason for commenting out the code was to copy and paste a solution from prior answer and determine if my line of code butted up against the solution didn't match but it did. Weird thanks for the help though! we're up and running again