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 trialSalem Osi
1,928 PointsNo idea what I'm doing wrong
I'm pretty sure I got everything right, but it's still giving me syntax errors, does anybody know what I'm doing wrong?
// I have imported java.io.Console for you. It is a variable called console.
String firstName = "Tyrone";
console.readLine (firstName);
String lastName = "West";
console.readLine (lastName);
console.printf ("First name:%s", firstName);
1 Answer
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsHi Salem Osi
Thanks for your question.
String firstName = "Tyrone";
Your first line of code is declaring a String and forcing it to be "Tyrone" which should not be the case. Remember the challenge requires you to collect input from the user and not to set a String to a value.
The way to get input from the user is to use the console's method readLine() to prompt for the name. readLine method takes in the message which will prompt the user.T he code goes like this:
//getting feedback from the user using console.readLine() method
String firstName =console.readLine ("what is your first name?");
String lastName =console.readLine ("what is your first name?");
When it comes to print out the info you can use the console's printf method as per the below code:
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);
Happy coding