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

matthew allen
matthew allen
972 Points

Something wrong but i cannot see what

can anyone help me out come with error telling me my syntax is wrong

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?"    );
isInvalidWord = (response.equalsIgnoreCase("No"));
if (isInvalidWord) {
          console.printf("that language is not allowed.  Try again. \n\n");
                   }
   }

2 Answers

I commented out all of the wrong code, but there were a number of issues:

  • You never declared a variable type for isInvalidWord.
  • They never asked you to print "that language is not allowed. Try again." I think you may have copied this from the previous videos
  • You forgot the while part of the do while.
// 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?");
/* <---------------------------------This block of code is not needed
    isInvalidWord = (response.equalsIgnoreCase("No"));
    if (isInvalidWord) {
        console.printf("that language is not allowed.  Try again. \n\n");
    }
*/ 
} while(response.equalsIgnoreCase("No"));

console.printf("Because you said %s, you passed the test!", response);
Chris Jones
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Jones
Java Web Development Techdegree Graduate 23,933 Points

I'm having a problem with my browser right now that's not allowing me to try the code challenge, but just by looking at your code, it looks like you're missing the WHILE clause of the DO-WHILE loop. Also, the isInvalidWord variable doesn't have a type declared. Looks like it should be Boolean. You also don't need the parenthesis around response.equalsIgnoreCase("No").

I'll check in again to see if I can attempt the code challenge. Hope this points you in the right direction for now. Let me know if you have any questions.