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

what am I missing?

I cant figure out whats wrong

Example.java
// 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");
  if(response.equals ("No"))
   console.printf("Do you understand do while loops");
}while (response.equals ("No"));
 console.printf("Because you said No, you passed the test!");

2 Answers

Hi Milly,

Your loop is mainly correct; it does the job. But you can delete the if statement in there as wellas the second question prompt; the printf isn't needed as your readLine does that for you.

Outside of the loop, the challenge wants an output that uses printf to insert the contents of response into the string. The output should be, "Because you said Yes, you passed the test!", or something like that.

So, insert a %s placeholder within the output string and use the format, printf("some text %s some text", response); to insert the right value in there.

I hope that helps,

Steve.

it didn't work

Can you post your code please?

String response ;
do {
  response =console.readLine("Do you understand do while loops");
  if(response.equals ("No")) // delete this line
   console.printf("Do you understand do while loops"); // delete this line
}while (response.equals ("No"));
console.printf( "Because you said %s, you passed the test!",response) // add a semi colon

Hi Milly,

I added some somments in your code. You've pretty much got that task nailed! Good work. :+1:

You should end up with this:

String response;

do{
  response = console.readLine("Do you understand while loops?: ");
} while(response.equals("No"));
console.printf("Because you said %s, you passed the test!", response);

Steve.

thank you so much :)

No problem! :+1: :smile: