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 trialAbhishek Dangol
Courses Plus Student 253 PointsWhat is wrong with this code
String firstName = console.readLine("What is your name? "); String lastname = "Dangol" String lastname = console.readLine;
// I have imported java.io.Console for you. It is a variable called console.
String firstName = console.readLine("What is your name? ");
String lastname = "Dangol"
String lastname = console.readLine;
3 Answers
Jeff Wilton
16,646 PointsDelete your second line, and make the lastName var do something similar to your firstName var.
String firstName = console.readLine("What is your first name? ");
String lastName = console.readLine("What is your last name? ");
zainsra7
3,237 PointsHi,
You need to use "console.readLine ()" to get the lastName from the user.
Here's the solution :
String firstName = console.readLine("What is your First Name? ");
String lastName = console.readLine("What is your Last Name?");
Challenge wants you to create a variable lastname in camelCase like this "lastName".
and then to use console.readLine() method just like you used to get firstName , to get the lastName in this part.
console.readLine() will print whatever you wrote in the parentheses("What is your Last Name") on the console and will wait for user to enter anything , and will return whatever user typed in as his last name. So we store that returned value in a string named "lastName".
I hope it answers your question, Happy Coding :)
- Zain
Fathima Fas-ha
6,847 PointsYou cant create two variables with same name and same type. String lastName="Dangal";//in this line you've missed a semicolon String lastName =console.readLine();//missing parentheses. both statements at once wont compile,it may cause compile error variable lastName is already defined ,therefore select one statement according to your need.