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
Meenakshi Bohra
1,182 Pointserror detection
String noun;
do{
noun= console.readLine("enter a noun: ");
if (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));
{
console.printf("That language is not allowed please try again later.. \n");
}
}
while (noun.equalsIgnoreCase("dork")|| noun.equalsIgnoreCase("jerk"));
String name= console.readLine("enter your name ");
String adjective= console.readLine("enter an adjective ");
noun= console.readLine("enter a noun ");
console.printf(" %s is a very %s girl \n , she lives in %s \n",name, adjective,noun);
the main problem is when i am giving any name apart from dork and jerk then too it is printing( the language is not allowed line ) which should not get print .
2 Answers
Steve Hunter
57,712 PointsHi there,
Which task/course is this in? Does it require a do|while or could you use a while loop?
Something like: Enter a noun - while noun equals(list of illegal words), keep looping and warning - else carry on through the code.
I've not got an IDE here, so this is just for an example - it'll be unlikely to work!
String noun = console.readLine("Enter a noun: ");
while (noun.equalsIgnoreCase("dork")|| noun.equalsIgnoreCase("jerk")) {
noun = console.readLine("That language is not allowed. Try again: ");
}
// rest of code here : no more noun code, though!!
String name= console.readLine("Enter your name: ");
String adjective= console.readLine("Enter an adjective: ");
Make sense?
Steve.
Ken Alger
Treehouse TeacherMeenakshi;
It looks like you have some extra semi-colons that are posing issues. The syntax for an if statement is:
if (someConditionToCheck.equals(somethingToCheckAgainst)) {
// do something magical
}
Notice that at the end of the conditional checking that there is not a semi-colon, like you have in your code.
Post back if you are still stuck.
Happy coding,
Ken