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 trialTojo Alex
Courses Plus Student 13,331 PointsI do not understand my error
Could you kindly explain what is wrong with this script and why it won't let me pass.
using System;
using System.IO;
using System.Net;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(BecomeZen());
}
public static string BecomeZen()
{
string zenResponse = "webClient.DownloadString("https://api.github.com/zen");
using(var webClient = new WebClient())
{
webClient.Headers.Add("User-Agent", "CodeChallenge");
}
return zenResponse;
}
}
}
4 Answers
Steven Parker
231,275 PointsRemember that "webClient" only exists inside the "using" block. So you'll need to call "webClient.DownloadString" from inside the block.
Also, watch for unbalanced quote marks when you create that assignment inside.
Tojo Alex
Courses Plus Student 13,331 PointsI fixed the unbalanced quote marks. So are you saying move the current string into the "using" block because when I do that it give me this : Did you call the 'DownloadString' method on the 'webClient' object? .
```using System; using System.IO; using System.Net;
namespace Treehouse.CodeChallenges { class Program { static void Main(string[] args) { Console.WriteLine(BecomeZen()); } public static string BecomeZen() {
using(var webClient = new WebClient())
{
webClient.Headers.Add("User-Agent", "CodeChallenge");
string zenResponse = "webClient.DownloadString"("https://api.github.com/zen");
}
return zenResponse;
}
}
}
Tojo Alex
Courses Plus Student 13,331 PointsI worked out a solution. Thanks Steven.
Steven Parker
231,275 PointsGood deal.
For the benefit of future readers, "zenResponse" should only be assigned inside the "using" block, it still needs to be declared in the method itself (the original declaration can remain as-is).