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

Code Challenge: Looping until the value passed. Where is my mistake?

Hey everyone. I am a little stuumped by part 3 of this coding challenge.

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

My code is:

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean invalidResponse;

do {
response = console.readLine("Do you understand do while loops?");
invalidResponse = (response.equalsIgnoreCase("No"));
}while(invalidResponse);
console.printf("Because you said <response>, you passed the test!");

And the error I receive is: Bummer! Did you use console.printf and to write out the formatted string with the response?

As far as I can see, I have done this correctly. Am I missing something ridiculously obvious?

Thanks guys :-)

1 Answer

Hi,

I just completed this challenge and here is my working code:

    // 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? ");

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

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

If we compare this to your code, there are few differences. Your way of doing is fine but there are few errors in your code

    // I have initialized a java.io.Console for you. It is in a variable named console. 
    String response; 
    boolean invalidResponse;

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

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

First, there are parenthesis around the (response.equalsIgnoreCase("No"));

Second, you are printing string <response> instead of the actual string-value.

[MOD: edited code blocks - srh]