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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Randolph Wiafe](https://secure.gravatar.com/avatar/15ffa8c2091985ff746945416f503333?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Randolph Wiafe
1,288 PointsDo While loop ends after 3 tries. Why is that?
So after entering all three isInvalidWord it tells me to Enter adverb. Does this have anything to do with how many words we have in isInvalidWord?
Enter noun: jerk
That language is not allowed. Try again.
Enter noun: dork
That language is not allowed. Try again.
Enter noun: nerd
That language is not allowed. Try again.
Enter adverb:
Code below in case that helps.
public class TreeStory {
public static void main(String[] args) {
Console console = System.console();
// Below is a multi line comment
/* 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 a __adjective__ __noun__. They are always __adverb__ __verb__.
// Here we convert a string to integer using the Integer class
String ageAsString = console.readLine("How old are you? ");
int age = Integer.parseInt(ageAsString);
// If age is greater than 13 contiune else exit
if (age > 13) {
String name = console.readLine("Enter name: ");
String adjective = console.readLine("Enter adjective: ");
String noun;
boolean isInvalidWord;
// Do while Loop
// Remember to declare variable outside of Do scope
do {
noun = console.readLine("Enter noun: ");
isInvalidWord = noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk") || noun.equalsIgnoreCase("nerd");
if (isInvalidWord) {
console.printf("That language is not allowed. Try again.\n");
}
} while (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));
String adverb = console.readLine("Enter adverb: ");
String verb = console.readLine("Enter verb: ");
console.printf("Tree Story \n --------------- \n");
console.printf("%s is a(n) %s %s. They are always %s %s.\n", name, adjective, noun, adverb, verb);
} else {
console.printf("You're not old enough!!!\n");
System.exit(0);
}
}
}
![Randolph Wiafe](https://secure.gravatar.com/avatar/15ffa8c2091985ff746945416f503333?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Randolph Wiafe
1,288 Pointssamuel zaffran Ah because the while is what makes it loop! Thank you very much!
![samuel zaffran](https://uploads.teamtreehouse.com/production/profile-photos/4637512/micro_IMG_20151118_213226_1_.jpg)
samuel zaffran
24,815 PointsYou're well come ! Of course, do something while a condition is checked, if the condition is no longer checked do not accomplish the code in the do section, simple as that ;) (I 'll just post the same answer in the answer section, if someone'll need it in the future)
1 Answer
![samuel zaffran](https://uploads.teamtreehouse.com/production/profile-photos/4637512/micro_IMG_20151118_213226_1_.jpg)
samuel zaffran
24,815 PointsIn your condition (while) you just asked to loop if the noun is equal to jerk or dork but not nerd, so when you enter nerd it's no longer a condition valable and it's get out out the loop... Not about the number of time your enter a noun !! Hope this will help !
samuel zaffran
24,815 Pointssamuel zaffran
24,815 PointsIn your condition (while) you just asked to loop if the noun is equal to jerk or dork but not nerd, so when you enter nerd it's no longer a condition valable and it's get out out the loop... Not about the number of time your enter a noun !! Hope this will help !