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
Leif Mohn
8,179 PointsJava Basics Getting Started Challenge task 4/4
So I'm trying to complete the challenge and on task 4, it requires printing to console the last name. I've tried this code in Workspaces and it works. But apparently I'm missing something. To me, it should be the same synta as task 3 since it's printing out the last name instead of the first name. Here's my code:
String firstName = console.readLine("What is your name? ");
String lastName = console.readLine("What is your last name? ");
console.printf("Hello, my name is %s\n", firstName);
console.printf("%s is learning how to write Java!\n", firstName);
console.printf("First name: %s\n", firstName);
console.printf("Last name: %s\n", lastName);
What am I missing?Thanks
2 Answers
Ken Alger
Treehouse TeacherLeif;
I am not sure how picky this particular challenge is, but you may try removing your escape codes (\n), making sure you have two spaces between the : and the %s, as well as removing the extra lines of code that aren't involved in this challenge, i.e.:
console.printf("Hello, my name is %s\n", firstName);
console.printf("%s is learning how to write Java!\n", firstName);
Other than that your code looks good.
Ken
Leif Mohn
8,179 PointsThanks Ken. Yeah, it was removing those 2 lines of code that did the trick. Annoying obvious as it was the one thing I didn't remove. Hrrgggrrreeeerrkkkk - that's the sound my brain just now made when it 'sploded.
Ken Alger
Treehouse TeacherRemember to use Duct Tape when coding to wrap around your head, that way when it does explode you can at least find all the pieces!
At any rate, pleased it all worked out.
Happy coding,
Ken