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 Looping until the value passes

Cas F
seal-mask
.a{fill-rule:evenodd;}techdegree
Cas F
Full Stack JavaScript Techdegree Student 21,170 Points

I've tested this in WorkSpace, and it does what the prompt is requesting, yet it still says to try again. Halp!

The prompt is to make a Do While loop that prompts the user for a response and continues to ask while the answer is "no". My code does this, I've tested it in a WorkSpace, however the challenge still prompts me to try again. I'm assuming there is a different way to complete this task that the challenge would prefer I use. Thoughts?

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do{
  response = console.readLine("Do you understand do while loops? ");
  if (response.equalsIgnoreCase("Yes")){
    console.printf("Congratulations!");
    System.exit(0);
  } 
} while (response.equalsIgnoreCase("No"));
Cas F
seal-mask
.a{fill-rule:evenodd;}techdegree
Cas F
Full Stack JavaScript Techdegree Student 21,170 Points

This also doesn't complete the challenge:

String response;
boolean answer;
do{
  response = console.readLine("Do you understand do while loops? ");
  answer = (response != "No");
  if (answer){
            console.printf("Congratulations!");
            System.exit(0);
  } 
} while (response.equalsIgnoreCase("No"));
Cas F
seal-mask
.a{fill-rule:evenodd;}techdegree
Cas F
Full Stack JavaScript Techdegree Student 21,170 Points

!!! SOLVED !!! Apparently I was being to advanced for the software check. see the following solution:

String response;
do{
  response = console.readLine("Do you understand do while loops? ");
} while (response.equalsIgnoreCase("no"));

1 Answer

Hey CAS! Glad you managed to solve this on your own, but a piece of advice I would like to offer is never ever do anything in the code challenges that you weren't explicitly told to.