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

Compiler Error

Hello,

I'm getting the following error when I try and run my code:

JavaTester.java:123: error: incompatible types: boolean cannot be converted to String isInvalidWord = console.readLine(response.equalsIgnoreCase("No")); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output

1 error

Does anyone have any suggestions for why I'm getting the error? I'm at a loss.

Thanks!

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean isInvalidWord;
do {
 response = console.readLine("Do you understand do while loops?  ");
 isInvalidWord = console.readLine(response.equalsIgnoreCase("No"));
 if (isInvalidWord) {
    console.printf("Why not?");
 }
} while(response.equalsIgnoreCase("No"));
foxtails
foxtails
3,655 Points

Jason is right. Here's the code that passed for comparing:

String response;
boolean responseIsNo;
do{
  response = console.readLine ("Do you understand do while loops?  ");
  responseIsNo = response.equalsIgnoreCase("No");
  if(responseIsNo){
  console.printf("Try again!");
    }
  }while (responseIsNo);

1 Answer

Since you've already got input from user for the string response, on the next line you just need to check whether it's equal to set the value of isInvalidWord rather than read another input. So i think it should read:

isInvalidWord = (response.equalsIgnoreCase("no"));