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

Why do I keep getting this message:"Your code took long to run"even if it less than 2 minutes. I am stuck and can't cont

I'am stuck and can't continue. Her's what I'm doing but keep getting errors. WHAT AM I DOING WRONG?

String noun;
do
{
  who = console.readLine("Who's there?  ");
  noun = ("banana");
  if (noun.equalsIgnoreCase("banana"))
  {
    console.printf("%s who?\n", who);
  }
}while (noun.equalsIgnoreCase("banana"));

2 Answers

Thanks Jason for your answer but I figured it out what I was doing wrong last night and everything went OK. Thank you once more for input.

Hi Salomon,

You have created an infinite loop. You've set noun to "banana" and then there isn't any other code to change it to something else. Then your loop condition is checking if it's equal to "banana" which is always true so your loop never ends.

The problem is that you have removed some of the existing code and added in extra code beyond what the challenge is asking you to do.

In task 1 you are first asked to wrap the 3 lines of starter code in a do while loop. You want to keep the 3 lines of code as is but wrap it all in a do while loop.

do {
console.printf("Knock Knock.\n");
String who = console.readLine("Who's there?  ");
console.printf("%s who?\n", who);
} while ;

Then it tells you that you should check in the condition if who is equal to "banana" and to also move the String declaration of who outside the do/while loop so that you're not declaring the variable over and over again inside the loop.

String who;
do {
console.printf("Knock Knock.\n");
who = console.readLine("Who's there?  ");
console.printf("%s who?\n", who);
} while (who.equalsIgnoreCase("banana")) ;

Let me know if you're still having trouble.