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
Emily Mitchell
Front End Web Development Techdegree Student 8,599 PointsStuck on Stage 1, Challenge 3, need help!
I'm stuck on the 4th task of challenge 3 in Java Basics Stage 1. The question reads as a duplicate of the 3rd task but with a different variable. However, when I change the variable it's not accepting it as correct. What am I doing wrong?
Task: Print out to the screen using the printf method on console, "Last name: " and the user's last name.
Code:
console.printf("Hello, my lastname is %s", lastName);
console.printf("Hello, my last name is lastName");
Response in workspace:
Bummer! Did you forget to pass the lastName parameter to the printf function?
6 Answers
Stone Preston
42,016 Pointsyour code for task 3 is also incorrect. task 3 expects the output to be "First name: " and the variable first name, so you need to change that. also you dont need these lines:
console.printf("Hello, my name is firstName");
console.printf("Last name: lastName");
those are not necessary and dont accomplish the task. the printf lines above them already accomplish that. all you need is:
String firstName = console.readLine("What is your name? ");
String lastName = console.readLine("What is your last name? ");
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);
Stone Preston
42,016 Pointsyour first line almost has it, but is not quite what the task is looking for:
console.printf("Hello, my lastname is %s", lastName);
however the task states: Print out to the screen using the printf method on console, "Last name: " and the user's last name.
so you need to make sure your output string matches what the task asked for
console.printf("Last name: %s", lastName);
Emily Mitchell
Front End Web Development Techdegree Student 8,599 PointsI just change my code to
console.printf("Last name: %s", lastName);
and got the the same error message in my original post.
Stone Preston
42,016 Pointscan you post a link to the challenge along with the full code you have in the editor?
Emily Mitchell
Front End Web Development Techdegree Student 8,599 Pointshttp://teamtreehouse.com/library/java-basics/getting-started-with-java/io
String firstName = console.readLine("What is your name? ");
String lastName = console.readLine("What is your last name? ");
console.printf("Hello, my name is %s", firstName);
console.printf("Hello, my name is firstName");
console.printf("Last name: lastName");
console.printf("Last name: %s", lastName);
Ken Alger
Treehouse TeacherEmily,
You are doing things correctly it looks like, just some text formatting that the challenge engine is specifically looking for.
// I have imported java.io.Console for you. It is a variable called console.
// Task 1
String firstName = console.readLine("First name: ");
// Task 2
String lastName = console.readLine("Last name: ");
// Task 3
console.printf("First name: %s", firstName);
// Task 4
console.printf("Last name: %s", lastName);
The challenge checker engine can, at times, be rather picky about what it wants.
I hope it helps, and welcome to Treehouse!
Ken
Emily Mitchell
Front End Web Development Techdegree Student 8,599 PointsThanks so much for your help Stone! The wording for the task really threw me off, especially since it accepted my code for the 3rd task.
Thanks again!