Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Looping until the value passes

Min ..
Min ..
648 Points

What 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

Example.java
// 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
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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"));

:information_source: 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! :sparkles: