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

Joel Muro
Joel Muro
2,884 Points

challange task if statement

Console.Write("C#"); string language = Console.ReadLine();

if (language =="C#") { Console.Write("C# Rocks!");

}

question is write code to print "C# Rocks!" to the console if language equals "C#". what am i doing wrong

7 Answers

Pablo Rocha
Pablo Rocha
10,142 Points

Hi Joel Muro - You have a "Console.Write("C#");" statement before the "string" declaration. That is not part of the solution. Remove it and you should be good to go.

Joel Muro
Joel Muro
2,884 Points

string language = Console.ReadLine();

if (language =="C#") {

System.Console.Write("C# Rocks!");

}

this worked

Pablo Rocha
Pablo Rocha
10,142 Points

Great! Please make sure to mark the best answer. Have fun with the rest of the course!

Joel Muro
Joel Muro
2,884 Points

it still wont take my answer though write code to print "C# Rocks!" to the console if language equals "C#". how should I write this code

Pablo Rocha
Pablo Rocha
10,142 Points

Take a look at my answer. If that does not work then provide us with the error message that is returned. The error message usually starts with "Bummer!".

Francis MacDonald
Francis MacDonald
2,759 Points

string language = Console.ReadLine(); if (language == "C#") { Console.WriteLine("C# Rocks!"); }

Remember it's just asking you to write the code that's required, not execute the program. You don't need to worry about making sure the correct input is passed in.

Joel Muro
Joel Muro
2,884 Points

great heres the next question 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.Write("language + "is not C#.");

} this is what I wrote . am I trying to do something it is not asking for

Pablo Rocha
Pablo Rocha
10,142 Points

You have an extra " before the language variable.

Joel Muro
Joel Muro
2,884 Points

great thanks . got it hey I wanna ask everyone is there a place where I could ask questions and here peoples feedback for software I'm writing ? besides this community

Pablo Rocha
Pablo Rocha
10,142 Points

Stackoverflow.com is great. There are other sites depending on what type of application you are developing.

Joel Muro
Joel Muro
2,884 Points

The following table describes my room temperature preferences. Print the message from the table when a user enters a number in the corresponding range. For example, if temperature is 21 the code should print "Just right." to the screen. Temperature (°C) Message Less than 21° Too cold! 21° to 22° Just right. Greater than 22° Too hot!

string input = Console.ReadLine(); int temperature = int.Parse(input);

if (temperature < 21 ) { System.Console.Write("Too cold!"); } else if (temperature = 21) { System.Console.Write("Just right."); } else if (temperature = 22) { System.Console.Write("Just right."); } else { System.Console.Write("Too hot!") }

this is my code what am I doing wrong?

Francis MacDonald
Francis MacDonald
2,759 Points

You should open a new question for each of these and mark correct answers as answer.

In any case. Take a look at your if (temperature { if condition. It's not correct.