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 trialAlpay Ozcan
260 PointsIF/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
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
Console.WriteLine(""+ language +"is not C#.");
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi 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!
Alpay Ozcan
260 PointsThanks a prompt reply! All clear