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

Andrew Minert
Andrew Minert
3,984 Points

Error with my Do While Loop.

I wrote this line of code, as directed in the video.

String name;
      do {
         name = console.readLine("Enter your name:  ");
        if (name.equals("dork") ||
            name.equalsIgnoreCase("jerk"))
          {
            console.printf("That Language is not allowed.  Try agian!");
          }
      } while (name.equalsIgnoreCase("dork") ||
              (name.equalsIgnoreCase("jerk"));

The error message is this

 Picked up JAVA_TOOL_OPTIONS: -Xmx128m                                                                                                                                    
Picked up _JAVA_OPTIONS: -Xmx128m                                                                                                                                        
TreeStory.java:31: error: ')' expected                                                                                                                                   
              (name.equalsIgnoreCase("jerk"));                                                                                                                           
                                             ^                                                                                                                           
1 error      

What did I do wrong?

1 Answer

Hey there, Andrew!

It took me a few minutes to find the error, but I believe it has to do with you not having enough parentheses ( ) around your while conditional.

You have

(name.equalsIgnoreCase("dork") || (name.equalsIgnoreCase("jerk"));

If you count the ()s from left to right, you'll see you have 7. A good rule of thumb is to ensure you always have an even amount of opening and closing parentheses. You're missing one on the left (or have too many, depending on how you want to format your code) at the beginning of the conditional loop. Your code should look like this:

while (name.equalsIgnoreCase("dork") || name.equalsIgnoreCase("jerk"));

Hope this helps! :-)

Andrew Minert
Andrew Minert
3,984 Points

Exactly right! Thank you for the help!