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
Kiyah Stokes
17,631 PointsWhat's wrong with my code?
We want to move that prompting code into a do while loop. Wrap the code into a do while and check in the condition to see if who equals "banana" so the loop continues. Remember to move your who declaration outside the do block.
console.printf("Knock Knock.\n");
String who = console.readLine("Who's there? ");
console.printf("%s who?\n", who);
while(who.equalsIgnoreCase("Banana"));
2 Answers
Jason Anello
Courses Plus Student 94,610 PointsHi Kiyah,
You need to set up a do/while block with curly braces and you also have to move the declaration of who above the loop.
String who;
do {
//Here is the prompting code
console.printf("Knock Knock.\n");
who = console.readLine("Who's there? ");
console.printf("%s who?\n", who);
} while(who.equalsIgnoreCase("Banana"));
Christian Andersson
8,712 PointsI believe you forgot your do command. Should be like this:
do {
...
} while ( );
Kiyah Stokes
17,631 Pointsthank you
Kiyah Stokes
17,631 PointsKiyah Stokes
17,631 Pointsthank you