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

Prompt the user with the question "Do you understand do while loops?" Store the result in a new String variable

Prompt the user with the question "Do you understand do while loops?" Store the result in a new String variable named response.

1 Answer

Daniel Hartin
Daniel Hartin
18,106 Points

Hi

Not sure what you are struggling with as there is no further explanation. I have pasted the answer below and will try to explain the reasoning to help you learn.

The first task asks you to define a variable named response that stores the users input after asking them a question, this can be done by calling console.readLine(), this method can take an argument prompting the user to what information we require.

The second task is a little more awkward and asks you to create the do while loop explained in the video. A do while loop will always execute once the code inside the curly braces (our prompt for information) will run continuously until the condition inside the parenthesis after the while key word is no longer met (which in this case is while the response from the user is equal to "No" we should keep looping).

The third challenge simply prints out the response inside a concatenated string.

String response;
do{
  response = console.readLine("Do you understand while loops");
}while (response == "No");

console.printf("Because you said %s, you passed the test!",response);

Hope this helps

Daniel