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 trialswm r
457 Pointswhats wrong here ?
i m not sure what mistake am I doing here , can you please help
// I have initialized a java.io.Console for you. It is in a variable named console.
String response ;
boolean task;
do {
response = console.readLine ("Do you understand do while loops? /n");
task = (response.equalsIgnoreCase ("No");
if (task)
{ console.printf("try again" );
}
}
while (task);
1 Answer
Mark Miller
45,831 PointsYou don't need any if() condition, the do{} while() is enough. Just do the line for console.readLine() while (response == "no" || response == "No") make sure to reassign the value of response each time the loop runs. You don't need a task variable nor the if().
Mark Miller
45,831 PointsMark Miller
45,831 PointsYou are missing a closing parenthesis ) where task is being assigned. You could just delete the left one. And I see a lone curly brace } with no left side partner also, three lines down from there. Additionally, I don't believe that the string value of "no" will be taken as a boolean, which is what task is to be assigned. With task declared to be boolean, task needs to take 0 or 1, True or False, not a string. You could declare it to be a string, but then any value it contains will be counted as True when it's evaluated in the if(). You should expand the if() condition to check for the value of "no" like this if( task == "no") and you'll need to change the declaration of task to be string instead of boolean.