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 trialLogan Balas
2,805 PointsHow to read user's response from the console and store it back into a variable?
read user response and return variable?
string value1 = "bookTitle";
value1 = "Bible";
System.Console.Write("Enter a book title: ");
"bookTitle" = System.Console.ReadLine();
1 Answer
Jennifer Nordell
Treehouse TeacherHi there!
I think maybe part of the problem is the understanding of instructions in the challenge. Technically speaking, your code shouldn't have passed the first step because the challenge explicitly asks you to create a variable named bookTitle. Instead, you created a variable named value1 and assigned the value of "bookTitle" to it. Then you reset the value of value1 to "Bible".
The prompt to the user though is executed just fine But then they want the new bookTitle (which should have been a variable name) to be overwritten by what the user puts in. Take a look at how I did it and see if it makes sense.
string bookTitle = "The Little Engine That Could";
System.Console.Write("Enter a book title: ");
bookTitle = System.Console.ReadLine();
I start with a variable named bookTitle which holds a string. I then assign a string to it with the title of a book. Next, I write out to the console a prompt to the user to enter their book title. Let's say they enter "Harry Potter". Then I take "The Little Engine that Could" and write over it with "Harry Potter". If we were to now display the value of bookTitle we would see "Harry Potter". Hope that helps!
Logan Balas
2,805 PointsLogan Balas
2,805 PointsThank you so much!
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherLogan Balas You're quite welcome!