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 trialTefo Temba Kebitseng
6,049 PointsChallenge Task 4 of 4 Using the console's printf method, display a message that says, "Last name: " followed by the l
I added the last line to the code which i thought would add the required message to be displayed like it happened with the first line.
now the error is that "i forgot to pass the lastName parameter"
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is your first name");
String lastName = console.readLine("What is your last name");
//camel-casing
console.printf("% is your name", firstName);
console.printf(" your name is %\n", firstName);
console.printf("% is your last name", lastName);
console.printf(" your last name is %\n",lastName);
console.printf("First name: %s\n", firstName);
console.printf("Last name: %s\n", lastName);
2 Answers
Jennifer Nordell
Treehouse TeacherIt's important to note that in challenges you need to do exactly what they tell you to do and no more. Even if functional outside the challenge, it can cause the challenge to fail. If you remove the first four console.printf
statements, your code passes! Hope this helps!
Jennifer Nordell
Treehouse TeacherThat's really strange. Because if I take this code and copy/paste it into the challenge, it passes all four steps. Take a look:
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is your first name");
String lastName = console.readLine("What is your last name");
//camel-casing
console.printf("First name: %s\n", firstName);
console.printf("Last name: %s\n", lastName);
Tefo Temba Kebitseng
6,049 PointsTefo Temba Kebitseng
6,049 PointsThank you Jennifer but it didn't help...it is nested question. The last line to display the last name gives an error that the value has not been passed whereas it got passed in the statement Line 2 ,second string declaration and assigning of the supplied input.