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

( and ) are expected but ( is an illegal start of type

while (isInvalidWord); turns out to ( is illegal start of type. but when i remove ( and ) it says they are expected.

*Please share your code *

import java.io.Console;

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
                                                  /* Some terms:
                                                     noun - Person, place or thing
                                                     verb - An action
                                                     adjective - A description used to modify or describe noun
                                                     Enter your amazing code here!
                                                     Adverb describes an adverb
                                                  */
      String ageAsString = console.readLine("how old are you?"  );
      int age = Integer.parseInt(ageAsString);
      if (age < 13) { console.printf("must be 13+ to use this program.\n"); 
                     System.exit(0);
                    }
      String name = console.readLine("enter a name:  ");
      String adjective = console.readLine("adjective:  ");
      String adverb = console.readLine("adverb:  ");
      String verb = console.readLine("verb ending in -ing:  ");
      String noun;
        do {
          noun = console.readLine("noun:  ");
          boolean isInvalidWord = (noun.equalsIgnoreCase("dork") || 
                              noun.equalsIgnoreCase("jerk") || 
                              noun.equalsIgnoreCase("nerd"));
          if (isInvalidWord){ console.printf("hey dont say that!try again!. \n\n");
                            }
        } while (isInvalidWord);
      console.printf("%s is very %s\n", name, adjective);
      console.printf(" your TreeStory:\n-------\n");
      console.printf("%s is a %s %s   ", name, adjective, noun);
      console.printf("they are always %s %s.\n", adverb, verb);
    }

}

1 Answer

Gabriel Precup
Gabriel Precup
4,565 Points

Watch the semicolumns! it shouldn't be placed right after the while, only if it's a do-while loop. So delete that semicolumn after the ).