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

C# C# Basics (Retired) Console I/O Console I/O

Logan Balas
Logan Balas
2,805 Points

How to read user's response from the console and store it back into a variable?

read user response and return variable?

CodeChallenge.cs
string value1 = "bookTitle";

value1 = "Bible";

System.Console.Write("Enter a book title: ");

"bookTitle" = System.Console.ReadLine();

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi 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 :thumbsup: 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! :smiley: