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 trialmatthew allen
972 PointsSomething wrong but i cannot see what
can anyone help me out come with error telling me my syntax is wrong
// 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
Philip Gales
15,193 PointsI 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
Java Web Development Techdegree Graduate 23,933 PointsI'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.