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 trialKylie Scott
2,823 PointsI can't figure out final step.
If the answer to response is 'yes' I want it to print out 'because you said yes, you passed the test'.
I've gone through various options but I can't get anything to work.
Can anyone help please?
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean answer;
do {
response = console.readLine("Do you understand do while loops?");
answer = response.equalsIgnoreCase("no");
if(answer) {
console.printf("Do you understand do while loops?");
}
} while(answer);
1 Answer
<noob />
17,062 PointsThis is the working code:
String response;
do {
response = console.readLine("Dou understand do while loops?");
} while(response.equalsIgnoreCase("No"));
console.printf("Because you said %s, You passed!", response);
you have few mistakes. u dont need to declare another variable called "answer" and u dont need an if statment because u use a while loop, as u know while loops used to loop until certain condition are met and for this case the loop will continue until ther user says no. in the "do" code block u just need to assign response to store the users input. then u want to keep prompt the user as long as he says No and u do it as i did, and finally if he didnt say No, u print the user's response.
Kylie Scott
2,823 PointsKylie Scott
2,823 PointsAh doh, so simple. Thank you very much for your help! I appreciate the quick reply :)