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 Censoring Words - Looping Until the Value Passes

Question about last exercise

I have find the solution for this exercise, but I want to know that why it is not working if I put response = prompt inside the do while loop ? Like This:

String prompt = console.readLine("Do you understand do while loops?");
String response; do{
response = prompt;
}while(response.equals("No"));

5 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

You should prompt in the loop, otherwise the value never changes.

Let me know if that hint does the trick!

kabir k
kabir k
Courses Plus Student 18,036 Points

Hi Craig,

I've enjoyed your Java course up until the Extra Credit. After we attempt this section, there's no link to a teacher's solution that one can use to compare with one's solution or if one gets stuck. It would be very helpful if you can provide a link to the teacher's solution for this Extra Credit section so that one can know what one is doing wrong (just like we have in the regular videos) and have the confidence to move forward to the next step.

I believe all treehouse courses with Extra Credit sections should have the teacher's solution links to help those having trouble completing it so that one doesn't have to spend too much time on them instead of moving on to learn the rest of the courses. It just seems like you have to choose between working on the 'Extra Credit' section (which obviously could help you get better) or abandoning it and moving on to learn about the rest of the course so you're not limited to learning a few concepts - which is quite frustrating. You shouldn't have to choose between these two.

Thanks

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Sahil,

I am not sure but I think that String respons must have a variable declaration like this:

String response = " ";

Please correct me if I am wrong

Grigorij

Hi Craig! Thanks for your answer. It works, but I want to know why the code that I have weiten above does not loop? I tought response has the same value as prompt so it should work. I hope you understand what I mean.

Craig Dennis
Craig Dennis
Treehouse Teacher

It does loop, it just loops indefinitely. Because response is always No, it'll loop until the end of time. response and prompt never change in the looping code, so since it doesn't have a chance to change it just runs that line trillions of times.

Make sense?

Thanks alot I got it.

I think I might have found another reason that it did not work: The console presented the error to me that the code did not work.