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

Cory Musick
seal-mask
.a{fill-rule:evenodd;}techdegree
Cory Musick
Front End Web Development Techdegree Student 8,545 Points

I can't figure out where to place the console.printf line for Challenge Task 3.

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

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"));
} while(response.equalsIgnoreCase("No"));
Jef Davis
Jef Davis
29,162 Points

My guess is inside the if block. Can you post the instructions for the problem?

Cory Musick
seal-mask
.a{fill-rule:evenodd;}techdegree
Cory Musick
Front End Web Development Techdegree Student 8,545 Points

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

I'm guessing it wants this to print if the user answers YES.

This is what I have come up with and its still sayings its wrong.

// I have initialized a java.io.Console for you. It is in a variable named console.

String response;

boolean isInvalidWord;

do {

response = console.readLine("Do you understand do while loops?");

isInvalidWord = (response.equalsIgnoreCase("No"));

if (response.equalsIgnoreCase("Yes")) {

console.printf("Because you said Yes, you passed the test!");

}

} while(isInvalidWord);

1 Answer

Jef Davis
Jef Davis
29,162 Points

So, it looks like the exercise is wanting you to pass the variable into the string, because that's something nice that can be done with printf. This is what I would do:

String response; 
do {
     response = console.readLine("Do you understand do while loops?");
     if (response.equalsIgnoreCase("yes")) {
          console.printf("Because you said %s, you passed the test!", response); 
     }
} while (response.equalsIgnoreCase("no"));