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 trialBalraj Duhre
Courses Plus Student 1,989 PointsWrite code to print "C# Rocks!". string language = Console.ReadLine(); Why do I keep getting this wrong?
I've tried everything and I keep getting it wrong. I don't know if I misunderstand on what I'm supposed to do.
string language = Console.ReadLine();
2 Answers
Calin Bogdan
14,921 PointsHello!
You have to use the if statement to check whether the input stored into the language variable equals "C#" and if it does you have to print the message.
Let's take it step by step:
// The first thing you write to the console will be stored here:
string language = Console.ReadLine();
// For example, if you type "Jamie", the value stored in the language variable will be Jamie.
// You have to check if the input (language variable) is equal to "C#"
// We can use the if statement to check this:
if (language.Equals("C#"))
{
// print "C# Rocks!"
}
// Well, even if the input equals "C#", it does nothing yet. Let's print "C# Rocks" if the input equals "C#"
// Finally, we use the Console.WriteLine() method to print the message
if (language.Equals("C#"))
{
Console.WriteLine("C# Rocks!");
}
Hope it helped!
Ioana State
213 PointsI dont understand why it doesn
t work. Could you please explain again?
string language = Console.ReadLine(); if (language == "C#") { Console.WriteLine = ("C# Rocks!"); }
It gives me an error: <<StudentsCode.cs(10,12): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer. Compilation failed: 1 error(s), 0 warnings>>
Thank you
Balraj Duhre
Courses Plus Student 1,989 PointsBalraj Duhre
Courses Plus Student 1,989 PointsThank you. It worked. I didn't understand the question I guess. I never thought about using an if statement.