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
Kevin Jervis
2,600 PointsI keep getting an error relating to line 33
I keep getting an error stating: TreeStory.java:33 : error cannot find symbol. Not sure what I'm doing wrong here.
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_aadjective_ noun. They are always_adverbverb_ 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 program.\n"); System.exit(0); } String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); String noun = console.readLine("Enter a noun: "); if (noun.equals("dork")) { String adverb = console.readLine("Enter an adverb: "); console.printf("That language. Exiting. \n\n"); System.exit(0); } 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);
}
}
2 Answers
michaelcodes
5,604 PointsHi there! After looking through the code there seems to have been a misplaced ending bracket } Below is the code with the bracket moved, please see the comment to see where the bracket was. There was also a few other pieces of code moved around. Compare to original
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_aadjective_ noun. They are always_adverbverb_
String ageAsString = console.readLine("How old are you? ");
int age = Integer.parseInt(ageAsString);
if (age< 13) {
console.printf("Sorry you must be at least 13 to use this program.\n");
System.exit(0);
}
String name = console.readLine("Enter a name: ");
String adjective = console.readLine("Enter an adjective: ");
String noun = console.readLine("Enter a noun: ");
if (noun.equals("dork")) {
console.printf("That language is not allowed. Exiting. \n\n");
System.exit(0);
} // This bracket here was placed lower below.
/* In the future when posting a question encase your code in
```java
My Code Here
```
This will make the Questioned formatted nice and readable :) */
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);
}
}
Daniel Phillips
12,632 PointsYes, like @michaelcodes said, if you define your adverb variable inside an if statement, it only gets created when that if statement is true (noun.equals("dork")). The compiler doesn't know what to do in the false case so it throws an error about you using adverb in the last print line since you never defined adverb before using it.
Kevin Jervis
2,600 PointsThank you Daniel. Everything is much clearer now. I appreciate the help.
Kevin Jervis
2,600 PointsKevin Jervis
2,600 PointsThat's awesome! I can see where I went wrong now. Thank you for your help. I appreciate it.
michaelcodes
5,604 Pointsmichaelcodes
5,604 PointsNo problem, glad I could help! If you're ever confused in the future don't hesitate to reach out on the forums here.
As always, take care and happy coding!