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

Maureen O'Neal
Maureen O'Neal
12,930 Points

Challenge 3 of 3, final section, Java basics

I can't get by this one, it previously asks for a do where loop, which I had, then this questions "Finally, using console.printf print out a formatted string that says "Because you said

<response>

, you passed the test!"", which I have written :

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

it doesn't throw any errors in the console, but I can't pass and get my badge. Yes, I tried response, even in the <> and that doesn't work either. Any ideas?

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

2 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Please refer to the following:

//Declare a String variable named response, then initialize it using double quotes
String response ="";

// The do while loop keeps asking the same question until "yes" is entered
//So we want to keep repeating when "no" is typed
// Exit the loop when "yes" is entered

do{
response = console.readLine("Do you understand do while loops?");  // "yes" or "no" is stored in the response variable 
// when someone types "no" the loop repeats
// when someone types "yes" the loop is exited
}while(response.equalsIgnoreCase("no"));

//After the loop exits, the following line prints to the console
console.printf("Because you said %s, you passed the test!",response); //task 3
Maureen O'Neal
Maureen O'Neal
12,930 Points

Of course, THANK YOU, it was rather obvious, but I didn't get it! Thanks again. :)