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

Galina Belyaeva
Galina Belyaeva
534 Points

Not sure why I get the Error

Hi Craig and all :)

I'm working on the Knock Knock challenge and I see this compiler error.

JavaTester.java:112: error: ')' expected who = (noun.equalsIgnoreCase("banana") || (noun.equalsIgnoreCase("orange")); ^ 1 error

I'm not sure why it's asking me for parenthesis, because it's already there.

Here is the code:

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

Please, help! Thank you :)

4 Answers

Ryan Hemrick
Ryan Hemrick
12,759 Points

Hello Galina,

Just looking over the syntax of the code you posted, it seems that you forgot a )

who = (noun.equalsIgnoreCase("banana") || (noun.equalsIgnoreCase("orange"));

There should be another ) after ("banana")

Hope this helps! :)

Galina Belyaeva
Galina Belyaeva
534 Points

Hi Ryan!

Thanks a lot! I just found that too! I have a different problem now...

I posted this task into my workspace and it gives me these errors (I actually had to make changes in the code given to us):

Knock.java:19: error: reached end of file while parsing } while(fruit); ^

and

Knock.java:20: error: reached end of file while parsing } ^

Here is the code

import java.io.Console;

public class Knock {

public static void main(String[] args) {
    Console console = System.console();

console.printf("Knock Knock.\n");

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

PS Sorry about bad formatting of this message, I'm still figuring out how to use it

Ryan Hemrick
Ryan Hemrick
12,759 Points

So I ran the code that you posted:

import java.io.Console;

public class TreeStory {

  public static void main(String[] args) {

    Console console = System.console();

    console.printf("Knock Knock.\n");

    String who; boolean fruit;

    do {

      who = console.readLine("Who's there? ");

      fruit = (who.equalsIgnoreCase("banana")) || (who.equalsIgnoreCase("orange"));

      if (fruit) {

        console.printf("%s who?\n", fruit); 

      } 

    } while(fruit); 

  }

}

And my result was as follows (after entering 'Ryan' when prompted):

Knock Knock.
Who's there? Ryan

I didn't receive an error when running the program. Did you compile the program with javac TreeStory.java? and then run the program with java TreeStory ?

Galina Belyaeva
Galina Belyaeva
534 Points

Hey Rayan!

You are right! At workspace, it doesn't show an error anymore (I put and extra } and it worked).

But when I entered this code in the task here, it showed errors...Can't check right now what's going on because there is a communication problem and my code can't be checked...

Thank you for your help, Rayan :)

Ryan Hemrick
Ryan Hemrick
12,759 Points

No problem! Happy coding!