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 trialJules Bekabisya
707 PointsJava Basics
Prompt the user with the question "Do you understand do while loops?" Store the result in a new String variable named response.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
String response = cnsole.readLine("Enter a respond: ");{
if(equelsIgn
console.printf("That is true");
}
}while(equelsIgnoreCare);
2 Answers
Allan Clark
10,810 PointsCheck your spelling on console and equalsIgnoreCase. Completely junk the if statement, that will be handled by the do-while. also make sure when you use equalsIgnoreCase you are calling the method on an Object and passing it a parameter like this:
response.equalsIgnoreCase("no");
Hope this helps
Grigorij Schleifer
10,365 PointsHi Jules,
let me modificate your code a little bit.
Do while loops look like this:
do {
//your code
}while(//condition);
And here your modified code:
String response;
// declare a variable outside the scope of the loop, so you can use it everywhere
do {
response = console.readLine("Enter a respond: ");
// typo inside console ( not cnsole)
// this will be executed at least once and if the condition inside the while parenthesis is true
// you donΒ΄t need to write String again, you declared a String variable "response" above
// you donΒ΄t need an if statement here
}while(response.equalsIgnoreCare("no"));
// while response is "no", repeat the part inside the do block
// you had a typo inside equalsIgnoreCase (not equels) :)
Let me know if you need more help
Grigorij