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 trialDavid Hinton
3,070 PointsCensoring words looping until the value passes
I just cannot seem to get my head around it, I guess coding isn't for me just so frustrating
import java.io.Console;
public class TreeStory {
public static void main(String[] args) {
Console console = System.console();
String ageAsString = console.readLine("What is your age? ");
int age = Integer.parseInt(ageAsString);
if (age < 13){
console.printf("Sorry you are too young. \n");
System.exit(0);
}
String name = console.readLine("Enter a name: "); String adjective = console.readLine("Enter an adjective: "); do { String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("Dork") || noun.equalsIgnoreCase("Jerk")) } console.printf("That language is not acceptable, Exiting program \n"); }
} while (noun.equalsIgnoreCase("Dork") || noun.equalsIgnoreCase("Jerk")); }
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); }
1 Answer
Jeff Wilton
16,646 PointsI can see a couple of problems with your code. First the 'if' statement inside your 'do' loop should start with an opening curly brace '{' but it starts with an ending one '}'. Fixing that and running your program should then give you the error that Craig explains in the video where the variable 'noun' is unknown in the while loop because it is declared inside the do loop. So from that point, refer back to the video around the 2:22 minute mark and keep following along to see how he fixes it.
Don't get too discouraged - keep at it and it will get easier, I promise! Feel free to ask lots of questions and somebody will try to help. :)
David Hinton
3,070 PointsDavid Hinton
3,070 PointsThank you! I took a break came back at it watched the video again and finished it fine!