Java Java Basics Perfecting the Prototype Censoring Words - Using Logical ORs

Rasmus Bøgelund
Rasmus Bøgelund
5,063 Points

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

james south
james south
Front End Web Development Techdegree Graduate 33,250 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"))
Buddhima Sehan
Buddhima Sehan
3,819 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.)