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 trialDeron Gomez
Courses Plus Student 2,571 PointsWhats wrong with my code??
String response; Boolean negativeResponse; do { response = console.readLine("Do you understand do while loops? "); negativeResponse = response.equalsIgnoreCase("No"); if(negativeResponse) { console.printf("Not a good answer! Try again!"); } } while(negavtiveResponse);
im getting a "illegal start of type error!
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
Boolean negativeResponse;
do {
response = console.readLine("Do you understand do while loops? ");
negativeResponse = response.equalsIgnoreCase("No");
if(negativeResponse) {
console.printf("Not a good answer! Try again!");
}
}
while(negavtiveResponse);
1 Answer
michaelcodes
5,604 PointsHi there! These coding challenges are very picky with what they are looking for. With this code they just want you to prompt the user for a variable called "response", and then continually loop while that variable is No. I changed up the code a little bit and commented out the stuff not needed:
String response;
//Boolean negativeResponse;
do {
response = console.readLine("Do you understand do while loops? ");
//negativeResponse = response.equalsIgnoreCase("No");
// if(negativeResponse) {
// console.printf("Not a good answer! Try again!");
//}
} while(response.equals("No"));
In practice the response.equalsIgnoreCase is good to use, as it will normalize the input. However with this challenge they don't require you to use it.
We don't need a boolean switch here as we can just continually loop the user while response is equal to No. (response.equals("No"))
I hope this helps!
Deron Gomez
Courses Plus Student 2,571 PointsDeron Gomez
Courses Plus Student 2,571 Pointsthanks!