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 trialHolly Bancroft
5,162 PointsProgram 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
7,097 Pointsi feel your if block is not properly idented go back and check it again
Mei Lee
3,339 PointsYour code checks if the input for noun is "dork". It doesn't check the inputs for name, adjective, and verb.