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

Abdullah Nazeer
Abdullah Nazeer
239 Points

Hi , what's wrong with my code?

import java.io.Console;

public class TreeStory {

public static void main(String[] args) {
    Console console = System.console();
  String name= console.readLine("What's Your name   /n");
  String race= console.readLine("Which race do you belong to  /n ");
  String monthOfBirth= console.readLine(" Which month were you born on/n");
  String ageAsString= console.readLine(" How old are you   /n "   );
  int age=Integer.parseInt(ageAsString);
  String noun;
 do{
    noun= console.readLine("Please type in a noun    ");
   if (noun.equalsIgnoreCase("dork")|| 
      noun.equalsIgnoreCase("FreaK")){
    console.printf("This language is not allowed, Try again");
    } while (noun.equalsIgnoreCase("dork")|| 
      noun.equalsIgnoreCase("FreaK"));
    if(age<13)
    {console.printf("Sorry you can't use this site\n");
    System.exit(0);} 

}

}

1 Answer

Robert Stefanic
Robert Stefanic
35,170 Points

Your brackets are a bit off. In your code, the curly bracket before your while loop closes your "if statement" that's nested within your do/while loop, and not the do/while loop that you have.

Try this:

public class TreeStory {

    public static void main(String[] args) {
        Console console = System.console();
        String name = console.readLine("What's Your name   /n");
        String race = console.readLine("Which race do you belong to  /n ");
        String monthOfBirth = console.readLine(" Which month were you born on/n");
        String ageAsString = console.readLine(" How old are you   /n ");
        int age = Integer.parseInt(ageAsString);
        String noun;
        do {
            noun = console.readLine("Please type in a noun    ");
            if (noun.equalsIgnoreCase("dork") ||
                    noun.equalsIgnoreCase("FreaK")) {
                console.printf("This language is not allowed, Try again");
            }
        } while (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("FreaK"));
        if (age < 13) {
            console.printf("Sorry you can't use this site\n");
            System.exit(0);
        }
    }
}