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

While loops in Java-

Finishing up the OR || while loops in Java. Within the exercise, added a few "invalidWords" which would prompt you to enter a new word. However, there is one invalid word (noun***) where it fails and then, prompts you to enter an adjective. Technically, it should prompt you to ask a new noun until you have given a String value that is not within the "isInvalidWord". Please see the code below-

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, you must be at least 13 years old to use this program.\n");
        System.exit(0); 
      }

     String name = console.readLine ("Enter a name:  ");
     String adjective = console.readLine ("Enter an adjective:  "); 
     String noun; 
    // words that are not allowed
     boolean isInvalidWord;  
      do {
         noun = console.readLine ("Enter an noun:  ");
         isInvalidWord = (noun.equalsIgnoreCase("dork")||
                          noun.equalsIgnoreCase ("jerk")||
                          noun.equalsIgnoreCase ("nerd"));
    // the word "nerd" seems to be failing the validation
         if  (isInvalidWord){
          console.printf("That language is not allowed. Try again! \n\n");
         } 
      } while (isInvalidWord);
     String adverb = console.readLine ("Enter an adjective:  ");
     String verb = console.readLine ("Enter a verb ending in -ing:  "); 

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

} 

See results below :

How old are you? 26
Enter a name: gabe
Enter an adjective: big
Enter an noun: nerd
That language is not allowed. Try again!

Enter an adjective:

2 Answers

Tried to demo your problem. The environment i was using didn't have console, so i ran with system.in

import java.util.*;

class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String noun;
     boolean isInvalidWord;  
    do {
      System.out.println("Enter an noun:  ");
     noun = sc.nextLine();
     isInvalidWord = (noun.equalsIgnoreCase("dork")||noun.equalsIgnoreCase ("jerk")||
                      noun.equalsIgnoreCase ("nerd"));
// the word "nerd" seems to be failing the validation
     if  (isInvalidWord){
      System.out.println("That language is not allowed. Try again! \n\n");
     } 
  } while (isInvalidWord);
  }
}

got:

Enter an noun:  
 Nerd
That language is not allowed. Try again! 

Enter an noun:  
 Nerd
That language is not allowed. Try again! 

Enter an noun:  
 dork
That language is not allowed. Try again! 

Enter an noun:  
 jerk
That language is not allowed. Try again! 

Enter an noun:  
 JeRk
That language is not allowed. Try again! 

Enter an noun:  
 aardvark

The program ended here. So unless you entered leading or trailing spaces when you tested, i'm at a loss.

Hmmm, thanks for the reply! I'll try this one out on NetBeans. Can't pin point it. I'll loop back if/when I find the bug.

Thanks again!

Are you recompiling the relevant class between saves? (a lot of people are so used to IDEs doing the heavy lifting and just forget to recompile)