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#

Can anyone help me figure out the C# code challenge for receiving inputs?

I'm trapped on the C# receiving inputs code challenge. Its asking me to read the users response from the console and store it back into the bookTitles variable. Here's my code as it stands: string bookTitle = "Dune"; System.Console.Write("Enter a book title: "); string entry = System.Console.ReadLine(); When I click on the check code button it says " Bummer! Did you set 'bookTitle' using user input. When I click on the preview button it just says "Enter a book title:" I'm not sure I understand what the code challenge is asking for. I watched the video several times and emailed and tweeted the instructor and got no response. Anyone out there. Please help me get past this thing!!

1 Answer

andren
andren
28,558 Points

The problem is that the challenge asks you to store the user input in the variable called "bookTitle", you are storing the user input in a variable called "entry" hence why the error message specifically states: "Did you set 'bookTitle' using user input."

The Teamtreehouse Challenge checker is pretty strict about what it accepts as answers. Whenever it mentions that it wants certain variable names or certain phrases printed out, you have to match those requirements exactly, or it will mark your code as wrong even if it the code is technically fine.

Okay so I reset the code so now I just have: string bookTitle = "Dune"; System.Console.Write("Enter a book title: "); So isn't the top string saving the users input to that string already? I guess I'm not seeing the proper procedure to store back something to a variable. Any thoughts and thank you for the post.

andren
andren
28,558 Points

No, in the top string you are "hardcoding" the name "Dune" to the variable, hardcoding is when you type something into your code that cannot be changed changed during the programs execution, the only way to change it would be to change the code itself.

Your code from before was mostly correct, the only problem with it was that you stored the result of "System.Console.ReadLine()" in a new variable called "entry", the task simply wanted you to take that result and store it in the bookTitles variable instead like so:

          bookTitle = System.Console.ReadLine();

Storing something back to a variable, in this instance, is just another way of saying that they want the variable set equal to the result.