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 trialJoel Muro
2,884 Pointschallange 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
10,142 PointsHi 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
2,884 Pointsstring language = Console.ReadLine();
if (language =="C#") {
System.Console.Write("C# Rocks!");
}
this worked
Pablo Rocha
10,142 PointsGreat! Please make sure to mark the best answer. Have fun with the rest of the course!
Joel Muro
2,884 Pointsit 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
10,142 PointsTake 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
2,759 Pointsstring 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.
Derek Etnyre
20,822 PointsSystem.Console.Write
Joel Muro
2,884 Pointsgreat 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
10,142 PointsYou have an extra " before the language variable.
Joel Muro
2,884 Pointsgreat 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
10,142 PointsStackoverflow.com is great. There are other sites depending on what type of application you are developing.
Joel Muro
2,884 PointsThe 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
2,759 PointsYou 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.