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 trialMin ..
648 PointsWhat is wrong with my answer?
I am doing this Task..
Challenge Task 2 of 3 Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop.
Here is my answer :
String response;
do { response = console.readLine("Do you understand"); if(response.equals("no")) { console.printf("again"); }
while(response.equals("no"));
Turns out there are tons of complier errors, I can't even guess what is wrong! lol
// I have initialized a java.io.Console for you. It is in a variable named console.
Challenge Task 2 of 3
Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop.
String response;
do {
response = console.readLine("Do you understand");
if(response.equals("no")) {
console.printf("again");
}
while(response.equals("no"));
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! The reason you're receiving the compiler errors is because you've got mismatched open and closed curly braces. In your do while loop you have two open curly braces but only one closed curly brace. But even if I fix that, it still doesn't pass.
You've also included an unnecessary if statement to print something. But when I remove that, it still doesn't pass.
The strings you are checking for should be "No" ... not "no". Note the capitalization. So if I remove the unnecessary if statement, fix the closed curly braces, and change the capitalization of no, it passes. Take a look:
String response;
do {
response = console.readLine("Do you understand");
} while(response.equals("No"));
While this does not cause the challenge to fail, I'd point out also that the "Do you understand" does not meet the specifications for the challenge. In some instances this will cause the challenge to fail. The correct question should be "Do you understand do while loops?".
Hope this helps!