Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Perform if

Viktor Zhyvotun
Viktor Zhyvotun
2,153 Points

Can't complete the coding challenge

This seemed to be an easy and straightforward task with an easy and straightforward solution. However, this code doesn't work, i get the "i typed bogus and it still printed C#...." response. I have no idea why. I tried to overcomplicate the code, tried to think that maybe i need to include bools somewhere , but i couldnt come up with any solution...

CodeChallenge.cs
string language = Console.ReadLine();
if (language == "C#");
{ 
    Console.WriteLine("C# Rocks!");
}
Viktor Zhyvotun
Viktor Zhyvotun
2,153 Points

Crisis averted, i found the mistake. It's about the semicolon after IF statement which is not needed. However that "i typed bogus..." response doesn't even remotely help to track down the mistake , and Preview function does not show it as well. Would be nice to have a clear indication what and where went wrong so I could've maybe come up with the answer myself rather than getting a straight answer from someone. Just a comment.

1 Answer

Steven Parker
Steven Parker
211,076 Points

Good job resolving your issue. :+1:

But that semicolon is not just "not needed", it alters the function of the program by completing the if with an empty then-statement. So the code following in the braces is no longer conditional and will always run.

The message about "I typed 'bogus'" was just the challenge telling you how it tested the function and what result it got. And there was nothing in the preview because while you altered the function of the program, your code was still "valid" in terms of language syntax.