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 trialHenry P
1,998 PointsStage 3 Challenge 2 printing the punch line
So I'm trying to print the punch line here, but I don't know what I'm missing. I executed the loop and now if everything checks it should print the variable which is who. But I am getting an error.
/* 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?
*/
//Here is the prompting code
String who;
do
{
console.printf("Knock Knock.\n");
who = console.readLine("Who's there? ");
console.printf("%s who?\n", who);
}
while(who.equals("banana"));
if (who.equalsIgnoreCase("banana");
console.print("%s", who);
2 Answers
David Galindo
Courses Plus Student 2,294 PointsHello Henry so If you remember in the last video we learned about booleans. this challenge has 2 task. first we need to create the do while loop , than the punchLine. so here is what it should look like this is the first part.
String who;
boolean answer;
do{
console.printf("Knock Knock.\n");
who = console.readLine("Who's there? ");
answer = (who.equalsIgnoreCase("banana"));
if (answer){
console.printf("%s who?\n", who);
}
}
while(answer);
than if the answer is "Orange" than we can print out the punchLine.
console.printf("%s you glad I didn't say Banana again?", who);
Hope this helps!!!
Henry P
1,998 PointsThank you!