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 trialGeorgia Margetts
1,662 PointsNow continually prompt the user in a do while loop. The loop should continue running as long as the response is No.
We should also not forget to declare the response outside of the 'do while' loop. I've tried looking on here at the other question that was asked but I cannot make head or tail of it, I just keep getting syntax errors!!
// I have initialized a java.io.Console for you. It is in a variable named console.
String response = "Do you understand do while loops?";
do {
console.readLine(response);
} while (response.equals("No"));
1 Answer
Steven Parker
231,184 PointsYou're close, but you don't want to assign "response" with the question. The question text can be used directly as the argument to "readLine" and you'll want to put the result of calling it into the "response" variable. Then the loop will be checking the user's answer instead of the question itself.
Before the loop, "response" can be declared without assigning anything to it.
Georgia Margetts
1,662 PointsGeorgia Margetts
1,662 PointsThank you so much!! I got it right!! :D