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

what am i doing wrong on task 2? var bookTitle; System.Console.ReadLine();

trying to figure out what i'm doing wrong on task 2 challenge for c# basics: here's my code var bookTitle; System.Console.ReadLine();

CodeChallenge.cs
System.Console.Write("Enter a book title: ");
var bookTitle;
System.Console.ReadLine();

1 Answer

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

Hi there, Michael! Currently you have attempted to make a variable named bookTitle with the var keyword. Any variable created this way must be given an initial value for the code to compile. Given that the challenge wants you to set the variable equal to what is returned by the System.Console.ReadLine() the easiest thing would be to initialize it with the string input by the user.

Also, while you are doing the System.Console.ReadLine() which is getting input from the user, what they put in is not being stored anywhere. It is sort of floating in limbo at this point.

Here is the line you're looking for:

var bookTitle = System.Console.ReadLine();

This stores the input from the user into the bookTitle variable, thus giving it an initial value.

Hope this helps! :sparkles: