Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Looping until the value passes

Cannot get answer to print

Can someone tell me why the "Because you answered 'Yes', you passed the test" will not print. Basically if the answer is not "No" I want this to be the response. Thanks! // I have initialized a java.io.Console for you. It is in a variable named console. String response; boolean answer; do { response = console.readLine("Do you understand while loops?"); answer = (response.equalsIgnoreCase("No")); if (answer) {console.printf("Do you understand while loops?"); } } while(answer); console.printf("Because you answered Yes, you passed the test")

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean answer;
do {
response = console.readLine("Do you understand while loops?");
  answer = (response.equalsIgnoreCase("No"));
  if (answer) {console.printf("Do you understand while loops?");
 }
}
while(answer);
console.printf("Because you answered Yes, you passed the test")

1 Answer

Brendon Butler
Brendon Butler
4,242 Points

Looks like you need to format our output string in your last line. You're also missing a semi-colon at the end of that line (I assume this was just a copy/paste issue.

Like in the previous tutorials, you'll want to use %s to identify strings to be replaced by the printf formatter method. Here's an example:

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