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

chase singhofen
chase singhofen
3,811 Points

i dont know what i am doing wrong?

i need to continually prompt user with a do while loop as long as the response is no

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response = console.readLine(" Do you understand do while loops?");
boolean response;
do {
  response = console.readLine(" Do you understand do while loops?");

  } while (response != "yes");

1 Answer

John Anselmo
PLUS
John Anselmo
Courses Plus Student 2,281 Points

I'm assuming you finished the first task?? If so...

Task 2/3: Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop.

I have redone this challenge just now and I found that the while condition requires you to check if it IS equal to No, and No exactly. Also, you didn't JUST declare response outside the do-while loop, you assigned it also, don't do that for this task :). So just declare it.

Here is what your code should look like for task 2/3:

String response;
do{
  response = console.readLine("Do you understand do while loops?");
} while(response == "No");        //make sure that No is capitalized

Now for task 3/3: Finally, using console.printf print out a formatted string that says "Because you said <response>, you passed the test!"

All you want to do is go outside the do-while loop and print "Because you said <response>, you passed the test!". Make sure you do this OUTSIDE the do-while loop:

String response;
do{
  response = console.readLine("Do you understand do while loops?");
} while(response == "No");
console.printf("Because you said %s, you passed the test!", response);
chase singhofen
chase singhofen
3,811 Points

i got is thx. i put capitol 'No'