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

Java Java Basics Perfecting the Prototype Looping until the value passes

do while loop

not understanding the do while loop... trying to get the knock knock joke to work..

KnockKnock.java
/*  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
console.printf("Knock Knock.\n");
Sting who;
boolean isInvalidWord;
do {
    who = console.readLine("Who's there?  ");
    isInvalidWord = (noun.equalsIgnoreCase("banana");
    if (inInvalidWord) {
      console.printf("%s who?\n" , who);
    }
   } while((who.equalsIgnoreCase("banana")
    console.printf("%s who?\n" , who);
  }
}

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jim;

Welcome to Treehouse!

Please see the discussion here along with my reply.

Ken

Ken Alger
Ken Alger
Treehouse Teacher

Jim;

If you still get stuck, or have difficulty with Task 2 here is another discussion on the same Challenge that includes Task 2 and may offer some additional insights.

Ken

Ungurusan Alin
Ungurusan Alin
780 Points

Hi Jim,

Try modifying

String who;

in

console.printf("Knock Knock.\n");
Sting who;
boolean isInvalidWord;

Thanks Ungurusan!