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
Thomas Buchstab
4,357 PointsCensoring Words - Looping until the value passes
I tried this already over and over. Can anybody please help me out.
here is my code...
Thanks for helping:-)
.............................................
String noun;
boolean isInvalidWord;
do {
noun = console.readLine("Enter a noun: ");
isInvalidword = (noun.equalsIgnoreCase("dork") ||
noun.equalsIgnoreCase("jerk"));
if (isInvalidWord) {
console.printf("That language is not allowed. Try again. \n\n");
}
} while (isInvalidWord);
2 Answers
Alberto Sanchez
2,268 PointsString noun;
boolean isInvalidWord;
do {
noun = console.readLine("Enter a noun: ");
isInvalidWord = (noun.equalsIgnoreCase("dork") ||
noun.equalsIgnoreCase("jerk"));
if (isInvalidWord) {
console.printf("That language is not allowed. Try again. \n\n");
}
} while (isInvalidWord);
Thomas Buchstab
4,357 Pointsthank you very much. finally it's working :-)
Alberto Sanchez
2,268 PointsAlberto Sanchez
2,268 Points//you are declaring the following variable in camel case
boolean isInvalidWord;
//but in this line you are using the following variable, isInvalidword,
isInvalidword = (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));
//observe "w" is lower case, it should be capital as you declared it
//remember Java is case sensitive, this may fix your code,
isInvalidWord = (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));