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

Ben Rodwell
Ben Rodwell
487 Points

Please Help

Hi I was wondering if anybody could help me fixing up this code. It looks right but it isn't excepting it. Please help

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
  do {
String response = console.readLine("Do you understand do while loops?  ");
console.printf("%s\n", response);
    isInvalidWord = (response.equalsIgnoreCase("No"));
    if (isInvalidWord) {
      console.printf("You must say yes. Try again. \n\n");
    }
  } while(isInvalidWord);

3 Answers

Has isInvalidWord been declared? I'm not seeing the declaration.

I see where you were going with the isInvalidWord logic in your code, but the challenge never asks you to do that. More often than not, the code challenges can be quite picky if you don't follow ALL the instructions (including the String grammar/spelling they're asking you to prompt for). So even if your code would work in your own java class that doesn't necessarily mean the challenge will pass you. The code below is all you will need to pass the challenges.

// I have initialized a java.io.Console for you. It is in a variable named console.
String response; //If you don't declare your 'response' String variable outside of the loop the challenge will fail you.
do {
response = console.readLine("Do you understand do while loops?");
} while(response.equals("No"));
console.printf("Because you said %s, you passed the test!", response);

Also, be sure to read over the error messages that you're given in the code challenges, because, most of the time they will lead you towards the correct answer.

Let me know if you have any other questions.

Mark Miller
Mark Miller
45,831 Points

The challenge says to declare the String response outside of the loop, and so you do that in step 1. Then, you're almost finished. Keep it simple. Just copy response down to the semicolon, and paste it inside of the do {} braces. Then this should continue to repeat while ______ blank! And the answer is already typed in your code. Your 'do' should repeat while(response.equalsIgnoreCase("no")). It looks like Derek has displayed it for you.