Java Java Basics Perfecting the Prototype Censoring Words - Using String Equality

Holly Bancroft
Holly Bancroft
3,840 Points

Program not blocking the word "dork"

My code looks exactly like the example as far as I can tell, and I have made sure everything is saved before running. It still allows me to input "dork". Here's the entire code just for reference, but I'm not sure why it's not 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?  \n");

      int age = Integer.parseInt(ageAsString);
      if(age < 13) {
      console.printf("You must be at least 13 years old to run this program.\n");
        System.exit(0);
                     }
      String name = console.readLine("Enter your name:  ");
      String adjective = console.readLine("Enter an adjective:  ");
      String verb = console.readLine("Enter a verb ending in 'ing':  ");
      String noun = console.readLine("Enter a noun:  ");

      if (noun.equalsIgnoreCase("dork")) {
      console.printf("That language is not allowed. Exiting. \n\n");
     System.exit(0);
      }

      String adverb = console.readLine("Please enter an adverb:  ");
      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);



    }

}```

2 Answers

pratyush raj
pratyush raj
7,093 Points

i feel your if block is not properly idented go back and check it again

Your code checks if the input for noun is "dork". It doesn't check the inputs for name, adjective, and verb.