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

It accepts the code, however, it does not catch the words? Can anybody tell me what I have done wrong?

String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("dork")) || noun.equalsIgnoreCase("jerk") { console.printf("Speak nicely! "); System.exit(0); } String adverb = console.readLine("Enter an adverb: "); String verb = console.readLine("Enter a verb ending with -ing: "); console.printf("%s %s %s %s %s", name, adjective, noun, adverb, verb); }

2 Answers

Buddhima Sehan
Buddhima Sehan
3,820 Points

Hey Rasmus Bøgelund,

Words is not working properly because in your if statement:

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

you have closed the parentheses of the if condition statement before the second condition. To correct the error, you can write the if statement as follows:

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

(Edited by moderator to format code blocks and fix grammar.)

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

i had a problem with this line:

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

until i put a set of parentheses around it like this:

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