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# C# Streams and Data Processing Streaming Data on the Net Become Zen

Become Zen Task 2

I can't seem to get this second task completed, I've tried naming the DownloadString to a different variable, then it asks me to set it to zenResponse. I've moved the string zenResponse = "" to after the using statement, I've tried setting it to zenResponse and then it won't compile. I'm at a loss currently if anyone could help.

Program.cs
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 = "";

            using(var webClient = new WebClient())
            {
            webClient.Headers.Add("User-Agent", "CodeChallenge");
            string zenResponse = webClient.DownloadString("https://api.github.com/zen");
            }

            return zenResponse;
        }
    }
}

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I feel like you're doing great and this looks to me simply like an oversight. You declare the string zehResponse not once... but twice. You already have it declared and initialized with string zenResponse = "";. Inside your using block, you are meant to assign a new value to zenResponse. The answer here is deleting the word string in the appropriate place. When I do that, your code compiles and passes both steps!

I think you can get it with these hints, but let me know if you're still stuck! :sparkles:

I tried taking string off inside the using statement and outside of it, task 2 still does not pass for me =/

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Michael Ashley I've tried this twice and confirmed it twice in two separate browsers. When I paste in your code from above and erase the extraneous string, I can click "Check Work" twice and it passes, which makes me wonder if there's some caching issue going on? My best advice to you right now is this: copy the code above, completely restart the challenge, paste in the code and remove the string, then hit "Check Work". If this doesn't work, let me know! :sparkles:

You were right, it was my browsers I was using. Copied my code to mobile and it worked fine. Thanks for all your help!