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 trialLi Yu
2,067 PointsProblem of if/else
I thought when typing string entry = Console.ReadLine(); in the first line already means that whatever words are entered, the words will show up as the string language. What is the problem in this program? And how could I print out the words that are entered? Thanks for the reply!
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
System.Console.WriteLine(language + "is not C#");
}
1 Answer
andren
28,558 PointsYour code is fine, language is equal to what was entered into to the program. But one thing to take notice of is that when you combine strings together they are merged without adding any spaces between them. Therefore in order to produce a sentence with proper spacing you have to add one manually. Either by adding a string that just contains a space, like this:
language + " " + "is not C#"
Or by adding a space at the start of the next string like this:
language + " is not C#"
Either way is fine, but you do have to do something to produce that space. The challenge checker for these challenges is pretty strict about text output. If it asks for a sentence with certain spacing it will mark your code as wrong it doesn't get exactly the sentence it wanted.
Li Yu
2,067 PointsLi Yu
2,067 Pointsandren, thank you so much! It is so exciting to pass this code challenge, and thank you very much for the detailed explanation.