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 trialStuart Ryan
2,886 Pointsneed help on task 3 now.
I can't seem to get passed this task. any help much appreciated.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean isInvalidWord;
do {
response = console.readLine("Do you understand do while loops?");
isInvalidWord = (response.equalsIgnoreCase("yes"));
if (isInvalidWord) {
console.printf("Because you said" response, "you passed the test!");
}
} while(isInvalidWord);
2 Answers
Grigorij Schleifer
10,365 PointsHi Stuart,
you think waaaaaay to complicated. You donΒ΄t need a boolean here. You have everything you need in your code already :)
You will need a while loop condition that says: while users response is equals to "No" repeat asking etc ....
Use this line
response.equalsIgnoreCase("yes")
for the while condition. After the User types "yes" the while conditionis is not true anymore and the compiler leaves the loop to print
"Because you said yes you passed the test!"
So for the TASK3 you can use your code from the if loop. But donΒ΄t forget to replace responce through a String formatter %s the challenge wants you to use.
See here for more details:
Let me know if you need more help ....
Grigorij
Stuart Ryan
2,886 PointsAppreciate your help.
I've coped your answer from the link you sent me and it's worked.
i don't have any variables defined and the workspace marked it correct. I get it. For me it's great following along and these tasks are really test your understanding.
do{ response = console.readLine("Do you understand do while loops");
}while(response.equalsIgnoreCase("no"));
console.printf("Because you said %s, you passed the test!", response);
Putting this in English it says while "no", [print] "do you understand do while loops" else [print] Because you said %s, you passed the test!
I got caught up trying to adapt where the video went.
Grigorij Schleifer
10,365 PointsHi there !
it should be:
while "no" or "No" ... go to the loop again and repeat the asking ,, while "yes" or "yes": leave the loop and go down to the next line !
You need to know that the compiler enters the while loop if the condition innside the parenthesid () is true and leaves it when the condition is false.
while(response.equalsIgnoreCase("no"));
// if the user types no ... the condition is true and the compiler stays in the loop and prints the asking sentence
// if the user types yes ... the condition is false ... the compiler leaves the loop and goes further down
Makes sense?