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
STAFF
Jennifer Nordell
Treehouse Staff

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
Jennifer Nordell
Treehouse Staff

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!