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 trialPatrick Dunn-Lawless
Courses Plus Student 339 PointstaskNumber errors?
When I run the attached code I get the following error messages:
JavaTester.java:102: error: while expected } ^ JavaTester.java:125: error: illegal start of expression taskNumber = 1; ^ JavaTester.java:125: error: ')' expected taskNumber = 1;
I've tried googling these but haven't had much success in finding an explanation for what they are referring to. What is taskNumber and how can I remove these errors from my code? Also I feel like there is a way to avoid using two booleans for this exercise (i.e. a way to say that isBanana is false) but haven't learned this yet. Any ideas?
console.printf("Knock Knock.\n");
String who = console.readLine("Who's there? ");
boolean isBanana;
boolean isOrange;
do { isBanana= (who.equalsIgnoreCase("banana"));
if(isBanana) {console.printf("%s who?\n", who);
console.printf("Knock Knock. \n");}
while(isBanana);
isOrange = (who.equalsIgnoreCase("orange"));
if(isOrange) {console.printf("%s who? \n", who);
console.printf("Orange you glad I didn't say Banana again?");
}
while(isOrange);
}
Patrick Dunn-Lawless
Courses Plus Student 339 PointsThanks for your answer, fixed!
1 Answer
Craig Dennis
Treehouse TeacherTo answer your question about taskNumber, somehow it broke our internal TestRunner that was checking your code. Sorry for the confusion!
Jorge Flores
7,864 PointsJorge Flores
7,864 Pointshi Patrick i would suggest to just wrap this lines in the do while loop console.printf("Knock Knock.\n"); String who = console.readLine("Who's there? "); console.printf("%s who?\n", who);
and complete the condition asking if the String who is "banana" remember that you might have a problem if you dont declare the variable who outside the loop because then the condition will not acknowledge the variable, also remember to ignore case on the condition. You will have something like this
String who; do{ console.printf("Knock Knock.\n"); who= console.readLine("Who's there? "); console.printf("%s who?\n", who);
}while(who.equalsIgnoreCase("banana"));
Also remember to read carefully because the punchline is only printed on the second step of the challenge, and you will substitue the word Orange with the variable who, you will have something like this:
console.printf("%s you glad i didnยดt say banana again?", who);
concerning to your code, you have a few mistakes on the comprenhesion of the problem, you need to keep asking the person untill he answers "banana", then you leave the loop. Good Luck, hope i was of any help.