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 trialali raafat
444 Pointscan i get help in this if/else
i need someone to tell me my mistake.
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
language == "is not C#";
}
2 Answers
markmneimneh
14,132 PointsIf you need anything printed, you need to add a print statement. Something like this
System.Console.WriteLine("is not C#");
instead of
language = "is not C#";
or you can even do this ...
language = "is not C#";
System.Console.WriteLine(language);
I am just pointing you into the right direction. You choose.
markmneimneh
14,132 PointsHello
the problem is in the else statement. else is executed when the condition in the if statement is not met. Therefore, else is what you want the code to do when if is by passed
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
language == "is not C#";
}
try this instead(please note the = insted of ==)
string language = Console.ReadLine();
if(language == "C#")
{
System.Console.WriteLine("C# Rocks!");
}
else
{
language = "is not C#";
}
If this answers your question, please mark the question as answered.
ali raafat
444 Pointsnothing was printed out its not working
ali raafat
444 Pointsali raafat
444 Pointswhat is the difference
ali raafat
444 Pointsali raafat
444 Pointsits not working in tried both