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

Tomer Bahar
Tomer Bahar
1,336 Points

Why is the "preview" blank? After writing the wrong code? Why in some cases I see correction and in other I don't?

After trying over and over to get my code right in this challenge, I kept on failing, So the first thing I did was as usual, going to the preview option to see where I got it wrong, but instead of seeing something to indicate where I was wrong, I saw a blank page. How come?

I'm stuck with that challenge and can't move forward. Please, what is the correct line of code for this challenge?

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean invalidWord;
do {
   response = console.readLine("Do you understand do while loops?");
   invalidWord = (response.equalsIgnoreCase("no"));
   console.printf("Because you said Yes, you passed the test!");
} while (invalidWord);

.

3 Answers

This is the code the challenge is asking for:

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do{
  response = console.readLine("Do you understand do while loops?  ");
}while(response.equalsIgnoreCase("no"));
console.printf("Because you said %s, you passed the test!", response);  //this will only run if the user types in a response that is NOT: "no", "NO", "No", or "nO".

If you would like more detail on the do while loop. You can check here, on another one of my forum posts about the exact same code challenge: https://teamtreehouse.com/community/im-learning-java-and-i-still-dont-understand-the-purpose-of-using-a-boolean-variable-while-using-a-do-while-loop

Tomer Bahar
Tomer Bahar
1,336 Points

Thanks a bunch Derek. It was a big help. Now I can move on :)

No problem. If my answer was of help to you I would really appreciate if you marked it as best answer