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 trialFrancis Stallings
2,132 PointsPrompt the user with the question "Do you understand do while loops?" Store the result in a new String variable named re
I've been working on this question for hours and I can't figure out it out. Do I need to supply a "yes" and "no" somewhere? An "if" variable? A boolean?
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
String response = console.readLine("Do you understsand while loops?" );
do {
response = console.readLine("Do you understsand while loops?");
if (response.equals("no"));
}
while(response.equalsIgnoreCase("no"));
3 Answers
Marina Alenskaja
9,320 PointsHi Francis!
You are almost right :-) You need to prompt the user, by calling console.readLine() and pass the question to the user as the argument. This way, the user can reply to your question and the reply will be saved in the response variable.
Try this:
String response;
do {
response = console.readLine("Do you understand do while loops?");
if (response.equals("no"));
}
while(response.equalsIgnoreCase("no"));
Francis Stallings
2,132 PointsThank you , but I tried this already and it didn't work. I tried it again and its still not passing. I don't understand what calling the console.readLine means exactly. I've been trying to type in things as I see them in the video and nothing passes.
Marina Alenskaja
9,320 PointsAre you sure you spelled everything correctly? I can see there is a spelling mistake in the code you first posted, which could give an error. And what error are you getting? Try to copy the exact code I've written, and if it doesn't work tell me what the error message is :)
Francis Stallings
2,132 PointsThank you, I did it and it passed but I don't know why. I don't see any difference from what I typed in and when I copied pasted. I was getting an error saying I needed to call the console.readLine.