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 trial

C#

Answer a Quiz Question on Basic IO in C#

Solve this Quiz Question:

Write code to print “C# Rocks!” to the console if language equals “C#”.

 When given this code to start with;

                  string language = Console.ReadLine();

3 Answers

Steven Parker
Steven Parker
231,184 Points

Here's a couple of hints:

  • you'll need an if statement with conditional expression to test the value in language
  • based on the condition, you'll use Console.WriteLine to print the phrase (remember punctuation!)

i mean can I just say the best way is just put the whole thing in WriteLine method. But I see the point of the exercise now. Thank you for your help

John Lukacs
John Lukacs
26,806 Points
string language = Console.ReadLine();
while (language == "C#") {
  console.Write.Line(C# Rocks!);   
}

Its still not passing

Steven Parker
Steven Parker
231,184 Points

You've got a few errors:

  • you need a test here (if), not a loop (while)
  • "WriteLine" is one word (no period in it).
  • you forgot the quotes around your string "C# Rocks!".

In future, be sure to start a new question rather than adding an additional question to one that was already answered. It was lucky that I just happened to spot this.

John Lukacs
John Lukacs
26,806 Points

Thank you. Im still a newb to C#