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

Aly Khedr
Aly Khedr
470 Points

UnKnown errors

I asked for help on my older version of this code just a minute ago, but I thought I figured out the problems. Know I'm not sure what the issue is.

CodeChallenge.cs
string language = Console.ReadLine();

if(language == "C#");
{
    Console.Write("C# Rocks!");
}
else();
{
    Console.Write("The Cake is a Lie");
}

3 Answers

Antonio De Rose
Antonio De Rose
20,878 Points
you've been not asked to do an else, hence you have to take the else completely out.
in if and else conditions, you should not end with a semicolon
string language = Console.ReadLine();

if(language == "C#")
{
    Console.Write("C# Rocks!");
}
Aly Khedr
Aly Khedr
470 Points

I tried that before I did the Else and it says it typed Bugus and it still printed C# rocks!

Ezequiel Hurt
Ezequiel Hurt
8,061 Points

Hi Aly Khedr, 1) You're only asked to write the IF clause, not an IF ELSE. 2) The Else clause only needs the curly brackets, because it doesn't have any condition, the condition is on the if. It's means that the ELSE clause will be executed only if the IF evaluates to FALSE.

To write an else, the code will be like this

string language = Console.ReadLine();

if(language == "C#")
{
    Console.Write("C# Rocks!");
}
else
{
    Console.Write("This languaje is not C#");
}
Antonio De Rose
Antonio De Rose
20,878 Points

try this

string language = Console.ReadLine();

if(language == "C#")
{
  System.Console.WriteLine("C# Rocks!");
}else{
  System.Console.WriteLine(language + " is not C#.");
}