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 trialNick Brigham
2,138 PointsChallenge Task 2 Perfecting the Prototype- Don't understand why my code is wrong?
It says "too many loops attempted". Why? Logically, this makes sense to me. While response = "No", prompt the question. Why is this wrong? What is the correct answer?
// I have initialized a java.io.Console for you. It is in a variable named console.
String prompt = console.readLine("Do you understand do while loops? ");
String response = prompt;
do {
prompt = console.readLine("Do you understand do while loops? ");
} while(response.equals("No"));
1 Answer
Rob Bridges
Full Stack JavaScript Techdegree Graduate 35,467 PointsHey there Nick, looks like you were slightly over-thinking this one and trying to make it more complicated than it had to be, a single String should be good to pass this.
I modified your code to below and it seemed to get through it.
String response;
do {
response = console.readLine("Do you understand do while loops? ");
} while(response.equals("No"));
I think the trouble was that you had two prompt set to console.readLine(); twice, and the grader was meant to pass "No" once, and your code would ask it to do too, just declaring this at the top would do just fine so that you have the scope to use response out of the loop, while still keeping the control flow of the program running smoothly.
Thanks, hope this helps, feel free to shout if to shout if it doesn't.