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

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
231,210 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.