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) Perform if / else

IF/ELSE

if(language == "C#") { System.Console.WriteLine("C# Rocks!"); } else { Console.WriteLine(""+ language +"is not C#.");

}

Someone please explain me where is the mistake?

thx

CodeChallenge.cs
string language = Console.ReadLine();

if(language == "C#")
{
  System.Console.WriteLine("C# Rocks!");
}
else 
{
Console.WriteLine(""+ language +"is not C#.");


}

2 Answers

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

Hi there! The problem lies in the string that you're printing in the else statement. You seem to understand that you need a space, but seem unsure how to do it. Right now, if I were to send in "Java", your code would print out:

Javais not C#.

But we would want it to print out:

Java is not C#.

Note the space between the value of language and the rest of the string. To do this, we can simply add an extra space in our string literal.

Console.WriteLine(language + " is not C#.");

This would print out the language we typed in with the appropriate spacing. Remember that when you print the value of a variable, no spacing is implied. If you want spacing, you have to explicitly put it somewhere.

Hope this helps! :sparkles:

Thanks a prompt reply! All clear