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 trialJason Tolman
277 Pointsdefinition of String who is outside the do block keep getting an error message
My definition of the "String Who;" is outside the do block ... Error message keeps asking me to move it outside the do block.
I kinda feel like this is the opening scene to Super Troopers - Where the kids are pulled over but the cop keeps asking them to pull over - and the drivers response is " I'm already pulled over, I can't pull over any further".
My String Who definition is already out side of the do block, I can't get it any more out side the do block.
What can I do ...
Thanks
/* So the age old knock knock joke goes like this:
Person A: Knock Knock.
Person B: Who's there?
Person A: Banana
Person B: Banana who?
...as long as Person A has answered Banana the above repeats endlessly
...assuming the person answers Orange we'd see
Person B: Orange who?
...and then the punchline.
Person A: Orange you glad I didn't say Banana again?
(It's a really bad joke that makes it sound like "Aren't you glad I didn't say Banana again?")
Let's just assume the only two words passed in from the console from Person B are either banana or orange.
*/
// ====BEGIN PROMPTING CODE====
String Who;
do {
// Person A asks:
console.printf("Knock Knock.\n");
// Person B asks and Person A's response is stored in the String who:
String who = console.readLine("Who's there? ");
// Person B responds:
console.printf("%s who?\n", who);
}
while(who.equals("banan"));
// ==== END PROMPTING CODE ====
4 Answers
ISAIAH S
1,409 PointsString Who;
Should be:
String who;
Jason Tolman
277 PointsWhen I hit the check work button it comes back with "Bummer, remember to move the definition of String Who outside the do block ... Which I have done.
Jason Tolman
277 PointsI actually get a error code when I use the "who" with a lower case .. but that is not what is stopping me from moving forward - It is telling me that I need to definition of string who outside the do block which it is.
Haig Sakouyan
409 PointsRemove 'String' from the below line of code
String who = console.readLine("Who's there? ");
I was stuck on this challenge and this post helped me as well. Thanks!
ISAIAH S
1,409 PointsISAIAH S
1,409 PointsWhat is the error message?