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 trialRhys Morris
Courses Plus Student 346 PointsCensoring Words - Looping Until the Value Passes.
I have entered the details of the code as demonstrated in the video, in their entirety. However I am receiving the following error...
TreeStory.java:39: error: reached end of file while parsing
}
^
1 error
I am getting the idea of what is being demonstrated with instructions being outside and inside the code block. Can I have a second pair of eyes on this?
This is my coding so far...
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 to use this progam.\n");
System.exit(0);
}
String name = console.readLine("Enter a name: ");
String adjective = console.readLine("Enter an adjective: ");
String noun;
boolean isInvalidWord;
do {
noun = console.readLine("Enter a noun: ");
isInvalidWord = (noun.equalsIgnoreCase("dork") ||
noun.equalsIgnoreCase("jerk"));
if (isInvalidWord) {
console.printf("That language is not allowed. Try again. \n\n");
}
} while(isInvalidWord);
String adverb = console.readLine("Enter an adverb: ");
String verb = console.readLine("Enter a verb ending with -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);
}
I have separated the middle code that is this lessons focus. As you may be able to see I have included a declaration outside the block...
String noun;
boolean isInvalidWord;
do {
code, code, code.
}
} while(isInvalidWord);
I'm not sure what it is I am missing. Any input would be gratefully appreciated.
R.
2 Answers
Ken Alger
Treehouse TeacherRhys;
You are headed in the correct direction, but it looks like you are over working this portion. When we obtain some string input, in this case assigned to a variable named noun
, we can check to see if it equals another string by noun.equals("someString")
. In the case of this program, we want to make sure that it equals something regardless of if the comparison string is upper or lower case, so we can use noun.equalsIgnoreCase("someString")
. We can put that inside an if
statement like this:
if (noun.equalsIgnorCase("dork") {
// do something magical
}
See if you can get that to function in your code and post back with any additional questions.
Happy coding and welcome to Treehouse!
Ken
Danial Goodwin
13,247 PointsThat error "reached end of file while parsing }" might be because you have too many closing brackets }
(or not enough opening ones). Make sure each opening and closing brackets have a match.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherEdited for markdown
Please see this post for instructions on how to post in the forum.
Ken