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

Brian Pedigo
Brian Pedigo
26,783 Points

What is wrong with this code?

This should work, I am missing something. But for what ever reason I cant pass the code challenge with it. Any ideas?

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.

String response = "yes";


do{
response = console.readLine("Do you understand do while loops?");  
} while(response.equalsIngoreCase("yes"));

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Brian;

Welcome to Treehouse!

A couple of things.

  1. We want to loop while our response is No, not while it is Yes.
  2. You have a syntax error in your equalsIgnoreCase() method. Check your spelling of the function. :wink:

Post back if you are still stuck, and happy coding.

Ken

Seth Kroger
Seth Kroger
56,413 Points

Looking over the challenge I see you're being asked to continue looping while the input is "no" not "yes". Fix that and you should be good to go.

Michael Hess
Michael Hess
24,512 Points

Hi Brian,

The challenge can be completed as follows:

// I have initialized a java.io.Console for you. It is in a variable named console.


String response;  //Declare response as String variable
do
response = console.readLine("Do you understand do while loops?"); //yes or no saved to response variable
while(response.equalsIgnoreCase("no"));  // Repeat loop if response is "no" 

//This is task 3
console.printf("Because you said %s you passed the test!", response);

Hope this helps! If you're still having issues we're here to help!