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 trialAndrej Pajenk
1,087 PointsFix the code so that it compiles, but don't change the intent of the code.
wtf
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
if (input == "quit")
{
string output = "Goodbye.";
}
else
{
input = Console.ReadLine();
string output = "You entered " + input + ".";
Console.WriteLine(output);
}
}
}
}
2 Answers
rmgvqegryz
3,970 PointsHello Andrej,
Take a good look at the challenge, because this code changes the intent of the code in the challenge. If you click preview, you 'll notice that the compiler has trouble with finding variabels such as output and input. So the answer would be to define the variabels in static void so that they are reachable for functions and methods. And inside the if-else-statement, you should not declare the variables, but rather use them (output = "some string").
Is this helpful? Can you pass the challenge?
Jason Weakley
2,502 PointsHere's my answer:
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
string input = Console.ReadLine();
if (input == "quit")
{
Console.WriteLine("Goodbye.");
}
else
{
Console.WriteLine("You entered " + input + ".");
}
}
}
}
Hope that helps!
Marci Tarpy
6,992 PointsMarci Tarpy
6,992 PointsThis was totally helpful to me! I passed the challenge, thanks for explaining it!