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 trialMichael Quiban
5,702 PointsMy if else statement isn't working on C#. Can someone see the issue for this to compile?
string language = Console.ReadLine();
if(language == "C#") { System.Console.WriteLine("C# Rocks!"); } else { System.Console.WriteLine(language + " is not C#."); }
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else {
System.Console.WriteLine(language + " is not C#.");
}
2 Answers
Erik McClintock
45,783 PointsMichael,
The challenge is being picky, and is looking for your string to match EXACTLY. Your code is correct, save for the fact that you have two space characters in the string " is not C#."
// You have:
" is not C#."
// You need:
" is not C#."
Remove the extra space character between the words "is" and "not", and your code passes just fine!
Erik
Emily Kolar
2,787 PointsIs it at least returning one of your writeline calls? The one under 'else' should at least be coming back.
If the 'else' writeline isn't getting printed, you could try just using Console.WriteLine() without the System namespace, if you're already "using System" at the top of your file... This might be nonsensical, but it really should be writing that 'else' string at the very least.
If that extra space that Erik pointed out was the problem, please let us know! I'm very interested.
Michael Quiban
5,702 PointsHi there Emily!
The issue did lie between the space problem. I was very lost for a brief moment! I thought I had this in my grasp.. I suppose TTH does a great job in teaching us to code and pay attention :) .
Michael Quiban
5,702 PointsMichael Quiban
5,702 PointsOh man. That was confusing! I kept looking at them both and I was beating myself up!
Thanks.