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 trialJames Huang
6,368 PointsI don't understand what the question is asking. Are they asking me to complete the full knock knock joke?
They ask me to print out the punchline, but then I need to make another do while loop to find "Orange". Do you need two variables to do this or can you do it with one?
/* 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?
...This repeats until Person A answers Orange
Person A: Orange
Person B: Orange who?
Person A: Orange you glad I didn't say Banana again?
*/
String who;
String who2;
boolean correctWord;
boolean correctWord2;
//Here is the prompting code
do {
console.printf("Knock Knock.\n");
who = console.readLine("Who's there? ");
correctWord = who.equalsIgnoreCase("Banana");
} while(correctWord);
console.printf("%s who?\n", who);
do {
who2 = console.readLine("%s who?\n", who);
correctWord2 = who2.equalsIgnoreCase("Orange");
} while(correctWord2);
console.printf("%s who?\n", who2);
console.printf("%s you glad I didn't say Banana again?". who2, who);
1 Answer
Ken Alger
Treehouse TeacherJames;
I have posted an answer here which may provide some assistance.
If it does not, post back on this thread to get additional assistance.
Ken