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

Final task for perfecting prototypes challenge

Hi there,

I am doing the final task for perfecting prototypes challenge, and it tells me, using console.printf, I should print out "Because you selected <response> you passed the test!" The compiler error shows an arrow with 1 error pointing to the first parentheses right before the word ("Because"); ^------------This one

Thanks for helping!

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.equalsIgnoreCase("no")) {
    console.printf("Try again!");
  } response = console.printf("Because you said, you passed the test"); //This is the line that I typed for the final task.
} while(response.equalsIgnoreCase("no"));

1 Answer

Nico Julian
Nico Julian
23,657 Points

Hello there,

I moved the declaration for the String response into the do-while loop to start. The bit of code in the do portion of the loop will run once no matter what, and then continue if the while condition at its end is true. So, you can remove the if portion and have something more similar to this.

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

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

I think the error you mentioned is showing because you are attempting to store the result of calling console.printf into your response variable.

response = console.printf("Because you said, you passed the test");

Since console.printf doesn't return anything, that could be the cause of it.