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 trialDaniel Lodestro
2,572 PointsI keep getting a compiler error and I cannot figure out how to pass this final challenge. Please help...
I just cannot seem to fix this. I googled the exact question, found another thread, and my code looked almost identical. I tried doing what one of the answers said to do, but I still got a compiler error.
Also, I now realize the console.printf does not need to be inside my do while loop, but I've tried placing it outside as well, and that did nothing.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response = console.readLine("Do you understand do while loops?");
do{
response = console.readLine("Do you understand do while loops");
if(response.equalsIgnoreCase("no")){
console.readLine(response);
String console.printf("Because you said %s, you passed the test!", response);
}
}while(response.equalsIgnoreCase("no"));
1 Answer
Grigorij Schleifer
10,365 PointsHi Daniel,
your code is almost fine. Needs just some modications.
- You don´t need the if-loop inside the while loop. The condition inside the while() is sufficient and the loop will repeat if the user says "no".
I deleted the first line of code:
String response = console.readLine("Do you understand do while loops?");
because this is something you need to ask the user again and again if he enters "No". So you can´t use it outside the while loop and you declaired it already inside the loop.
And the last TASK needs you to write
console.printf("Because you said %s, you passed the test!", response);
But this code needs to be outside the while loop. Only if the users answer is Yes this line of code will be printed because the compiler leaves the loop and enters the next line. If you let it inside the loop it will be printed every time the user says "no".
Here the changed code:
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);
Let me know if you are still stuck.
Grigorij
Daniel Lodestro
2,572 PointsDaniel Lodestro
2,572 PointsThank you so much Grigorij!
It makes much more sense now. I'm very new to this, but at the end of each video and following along with the exercises, I still feel like I'm not fully absorbing the material. Anything you'd recommend?
I feel as though the videos move very fast, and I might need to circle back and do everything twice, unless you think this is somewhat normal for someone who hasn't coded anything, ever!
Thanks again, I really appreciate you taking the time to help me out.
-Dan
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHi Dan,
I had the same feelings. I had so much problems to understand the logic, the OOP concepts and Craing :). After the Java Data Structures Track I was competely LOST IN SPACE :) ....
BUT then I rewatched the whole damn JAVA OBJECTS and Data Structures Track ... It took me 2 month to do so, but I had a complete different experience of learning. I know that you want learn fast and get more learning success for your money, but JAVA is a beast and sometimes I think Java is a lady, that wants to be conquered ....
Don´t give up ... rewatch videos .. watch YouTube if somethimg is unclear and read books ...
Don´t forget Java is a dragon ... If you want to hit the sky with it, You need to learn how to fly ... :)
Sorry for my horrible english ...
Grigorij
Daniel Lodestro
2,572 PointsDaniel Lodestro
2,572 PointsThanks for all your help Grigorij, I truly appreciate it.
I think I'm going to shelve Java for now, and switch to Python. After cruising through a few of the lessons in Python yesterday, it seems like I'm getting the hang of it much faster. Do you think it will help to learn that first, then go back to Java? Already it seems like the syntax is much, much easier to memorize and understand.
Thanks again!
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey go to Python and stick to it. Python is very popular and easy to jumpt into it.
Look this video. There you will find a subjective explanation above the Top 10 for the year 2106 but it realy informative.
https://www.youtube.com/watch?v=Z56GLRXxh88
And again ... See you in the forum coding ninja :)
Grigorij