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

Scott Sanders
PLUS
Scott Sanders
Courses Plus Student 1,826 Points

do while loops

String response; do{ String response = console.readLine("Do you understand do while loops?"); if (response.equalsIgnoreCase("no")) {console.printf("try again");} }while (response.equalsIgnoreCase("no"));

this is the code i have done for the exercise ^ and it dosn't work

String noun; do{ String noun = console.readLine("Enter a noun: "); if (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")){ console.printf("That language is not allowed try again/n/n");} }while(noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"));

And this is code that works in the treestory What am i doing wrong

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

The problem, I believe (although it's sort of difficult to read your code here) is that you're going way above and beyond what they're asking you to do. And while it may be functional, and it may be the smarter thing to do, it may still cause the challenge to fail. It's always a good idea to not do anything they don't explicitly ask for. I think the culprit may be the equalsIgnoreCase in this situation. Take a look at the code that passes:

String response;
do{
  response = console.readLine("Do you understand do while loops?");
} while(response.equals("No"));

edited for additional note

Additional note: They don't say to print anything with "Try again".

Scott Sanders
PLUS
Scott Sanders
Courses Plus Student 1,826 Points

Thanks yeah sorry about the code it looked nice until i hit to post the question then it smashed it all together but that was it the ignore case was stopping it all up

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Glad you got it working! Strange though (in my humble opinion) that they'd leave out the equalsIgnoreCase from the challenge when they just presented it.

Scott Sanders
Scott Sanders
Courses Plus Student 1,826 Points

i find they do that quite a bit in the basic classes they show you something and then the challenge comes along and they don't want you to use it