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 trialChristopher Anderson
1,601 PointsPrint “C# Rocks!” if language equals “C#” otherwise print language + “ is not C#.” So if I entered "Cheese" then "Cheese
Print “C# Rocks!” if language equals “C#” otherwise print language + “ is not C#.” So if I entered "Cheese" then "Cheese is not C#" would be printed to the screen.
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
System.Console.WriteLine("Bogus is not C#.");
}
Jason Anello
Courses Plus Student 94,610 PointsHi Christopher,
"bogus" was what the teacher chose to test the else branch. Your code passes because that's what was being tested. I think you must have seen the error message and thought you were supposed to hard code bogus in the else part.
You wondered why you couldn't put System.Console.WriteLine(language + " is not C#.");
Did it not work when you tried that? That does pass and it's what the challenge is intending you to do. That way it responds properly to any language entered that's not "C#"
Tagging Jeremy McLain
Is it possible to get 2 tests on the else branch to prevent this?
Jeremy McLain
Treehouse Guest TeacherYes "bogus" is just what the code challenge uses to test it. I can change it to test using a random word so that it doesn't confuse students in the future.
2 Answers
Ethan M
10,637 Pointsstring language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
System.Console.WriteLine(language + " is not C#");
}
Christopher, you would want to use string concatenation to grab the value of language if the response is not equal to C#. Bogus wasn't supposed to be used otherwise the program would assume the user typed Bogus.
Christopher Anderson
1,601 PointsThank you all for helping me, and thank you Mr.Mclain for being a great teacher and responding to my questions, i'm glad to be a Treehouse member.
Christopher Anderson
1,601 PointsChristopher Anderson
1,601 PointsWHY CANT I PUT
else { System.Console.WriteLine(language + " is not C#."); }
and why Bogus what does it mean