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 trialCory Musick
Front End Web Development Techdegree Student 8,545 PointsI 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"));
// 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"));
Cory Musick
Front End Web Development Techdegree Student 8,545 PointsFinally, 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
29,162 PointsSo, 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"));
Cory Musick
Front End Web Development Techdegree Student 8,545 PointsThat was it. Thank you so much! I forgot about the %s.
Jef Davis
29,162 PointsJef Davis
29,162 PointsMy guess is inside the if block. Can you post the instructions for the problem?