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

doesnt work

I cannot find the problem here. It looks right to me, please help. Here is my code, then error messages. Keep in mind I used 'place' instead of 'noun', and had one more 'or' statement to include the word 'nerd'.

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!
    */
  String ageAsString = console.readLine("How old are you?   ");
  int age = Integer.parseInt(ageAsString);
  if (age < 13) {
    //insert exit code
    console.printf("Sorry you must be at least 13 to use this.\n");
    System.exit(0);
  }  
  String name = console.readLine("Please enter a common name:   ");
  String place;
  boolean isInvaidWord;
  do {
    place = console.readLine("Please enter a specific place:   ");
    isInvalidWord = (place.equalsIgnoreCase("dork") || 
                     place.equalsIgnoreCase("jerk") ||
                     place.equalsIgnoreCase("nerd"));
    if (isInvalidWord) {
      console.printf("That language is not allowed. Try again. \n\n");
    }
  } while(isInvalidWord);
  String injury = console.readLine("Please enter a type of injury:   ");
  String objectFoundInAPark = console.readLine("Please enter a object you would find in a park:   ");
  console.printf("My TreeStory:\n-----------\n");
  console.printf("%s went to the %s and he got a %s\n while he was sitting on a park %s.", name, place, injury, objectFoundInAPark);


}

}

//errors next

TreeStory.java:25: error: cannot find symbol
isInvalidWord = (place.equalsIgnoreCase("dork") ||
^
symbol: variable isInvalidWord
location: class TreeStory
TreeStory.java:28: error: cannot find symbol
if (isInvalidWord) {
^
symbol: variable isInvalidWord
location: class TreeStory
TreeStory.java:28: error: illegal start of type
if (isInvalidWord) {
^
TreeStory.java:31: error: cannot find symbol
} while(isInvalidWord);
^
symbol: variable isInvalidWord
location: class TreeStory
TreeStory.java:31: error: illegal start of type
} while(isInvalidWord);

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Neil;

Welcome to Treehouse!

You have isInvaidWord as the variable name when you declare it and isInvalidWord when you are using it.

Ken

Wow. Silly me. Guess its time for bed!! Thank you for such a timely response so late at night!! Feeling more confident in my decision to join TreeHouse!