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.

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

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