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

JavaTester.java:110: error: variable isInvalidWord might not have been initialized

String who;
boolean isInvalidWord;
do{
who = console.readLine("who's there?  ");
if(isInvalidWord);{
console.print("%s who?")
}while(isInvalidWord)
Stone Preston
Stone Preston
42,016 Points

can you provide some more context? is this a challenge? if so can you post a link to it?

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jaden;

Welcome to Treehouse!

It appears you are working on the Looping until value passes challenge in the Java Basics course, correct?

If so, and going strictly based on the code you posted, you are missing some line ending semi-colons and other important facets of the challenge.. Additionally, I think you are over-complicating what the task is asking. You can complete the challenge without an if statement, as well as without the creation of a separate Boolean variable.

Something along the lines of:

String who;
do {
console.printf("Knock Knock.\n");
who = console.readLine("Who's there?  ");
console.printf("%s who?\n", who);
} while(who.equalsIgnoreCase("banana"));

should suffice.

Do you follow along with what the above code is doing?

Happy coding,

Ken

Wow, you were right thanks so much

You also missed the "who" variable as your second param in the printf

console.print("%s who?", who);