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

Why is my code not working?

I am using the or operators. Yet, nothing is working.

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {

Console console = System.console();

String ageAsString = console.readLine("How old are you? ");

int age = Integer.parseInt(ageAsString);

  if (age < 13)
  {
    console.printf("You are too young to use this program\n");
    System.exit(0);
  }

String name = console.readLine("Enter you name: ");
String adjective = console.readLine("Enter a Adjective: ");
String noun = console.readLine("Enter a noun: ");

  if (noun.equalsIgnoreCase("Dork")) || 
      noun.equalsIgnoreCase("Jerk"))
  {
    console.printf("You are not permitted to say this. EXITING! \n\n");
    System.exit(0);
  }

String adverb = console.readLine("Enter a adverb: ");
String verb = console.readLine("Enter a verb: ");

   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);

} }

3 Answers

Hi Leon

You've just put an extra closing parenthesis around your "Dork" test.

It should be as below otherwise the or and following condition is outside of the if statement:

    if (noun.equalsIgnoreCase("Dork") || 
          noun.equalsIgnoreCase("Jerk"))

Hope it helps!

There is a mistake in the way you close your parenthesis....you have added an extra one which is not needed

(noun.equalsIgnoreCase("Dork")) || 
      noun.equalsIgnoreCase("Jerk"))

change that to

(noun.equalsIgnoreCase("Dork") ||  noun.equalsIgnoreCase("Jerk"))

Thank you both very much.

you are welcome