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

Anas Rida
Anas Rida
8,183 Points

What am I doing wrong?

if (adjective.equals("naughty") || (adjective.equals("bad")) { console.printf("You are not allowed to use this kind of language you dirty rascal!!!!!\n\n"); System.exit(0); }

I am typing this code, but I am getting the following error

TreeStory.java:21: error: ')' expected

the arrow points to the curly bracket. did I miss something??

Thanks in advance

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Anas,

add a third round bracket to the if statement

if (adjective.equals("naughty") || (adjective.equals("bad"))) {  // a third round bracket added

console.printf("You are not allowed to use this kind of language you dirty rascal!!!!!\n\n"); 
System.exit(0); 
}

Let me know if this was the solution

Grigorij

Anas Rida
Anas Rida
8,183 Points

Thanks you for answering my question. I was actually able to figure it out. I added a third bracket and it worker. I also removed the bracket after the || and left two brackets at the end, and it also worked. However I am not sure which is considered the best solution, and less problematic in the future. If you could shed some light on this I would be very grateful.

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Anas,

try to write code that is easy to write and to read. So you have already done the best solution by deleting a bracket and made your code less "heavy" :)))

Grigorij