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 - Looping Until the Value Passes

Error

Im getting this error, how do i fix this? TreeStory.java:27: error: cannot find symbol
isInvalidWord = (noun.equalsIgnoreCase("dork") ||
^
symbol: variable isInvalidWord
location: class TreeStory
1 error

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Have you defined the variable isInvalidWord before using it? You should have the line:

boolean isInvalidWord;

Stephen Emery
Stephen Emery
14,384 Points

Before to do loop you need to define the boolean. That way the program knows the variable inside and outside the loop. If you put it directly in the loop, the outside code can't "see" it. Try this:

boolean isInvalidWord; do { noun = console.readLine("Enter a noun: "); isInvalidWord = (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")); if (isInvalidWord) { console.printf("That is unacceptable language :( Please try again.\n"); } } while(isInvalidWord);

Stephen Emery
Stephen Emery
14,384 Points

Sorry the comment box did not keep my code tabs and separations. Look for the ";" to see the breaks.