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

What am I doing wrong? Getting many errors?

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 a noun
        Enter your amazing code here!
    */
  /*____name ___ is a ___adjective __ __ noun __. They are always __adverb __ __ verb __.*/
         String ageAsString= console.readLine("How old are you?  ");
      int age = Integer.parseInt(ageAsString);
      if (age < 13) {
       //insert exit code
        console.printf ("Sorry ou must be at least 13 to use this program. \n");
        System.exit (0);
      }
                String name=console.readLine("Enter a name:  ");
                String adjective=console.readLine("Enter an adjective:  ");
                boolean isInvalidWord;
                do {
                noun=console.readLine("Enter a noun:  ");   
                    isInvalidWord = (noun.equalsIgnoreCase("dork")||
                                                        noun.equalsIgnoreCase("jerk"));
                if (isInvalidWord){
                    console.printf("That language is not allowed. Try again... \n\n");
                    }
                } while (isInvalidWord);
      String adverb=console.readLine("Enter an adverb:  ");  
                String verb=console.readLine("Enter a verb ending in -ing:  ");
    }

                console.printf ("Your TreeStroy: \n--------------\n");
                console.printf ("%s is a %s %s.  ", name, adjective, noun);
                console.printf ("They are always %s %s. \n", adverb, verb); 

    }

2 Answers

The first thing i'm noticing is that your last 3 lines appear outside the main method. Other than that it is hard to tell where else to look without the actual errors you are receiving. If this is not what the error is, please post which errors you get so we may assist further.

Cainan Barboza
Cainan Barboza
5,508 Points

You didn't declare the noun variable as a String outside of the code block.

Declare the noun variable as

String noun;

outside the codeblock before assigning it the value inside the codeblock.