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# Basics (Retired) Perfect Final

Tomasz Sporys
Tomasz Sporys
11,258 Points

Funny that it works in Visual Studio but not in "Treehouse Studio":(

What's up folks? How is this code wrong?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");

           int user = int.Parse(Console.ReadLine());

            for(var i = 0; i < user; i++){

               Console.WriteLine("Yey!");

            }

            Console.ReadLine();
        }
    }
}
Hendrik Heim
Hendrik Heim
1,012 Points
for(var i = 0; i < user; i++){

               Console.WriteLine("Yey!");

            }

instead of var try int.

It's a compiler issue I guess.

EDIT: or just the "Yay" :P

3 Answers

Sam Baines
Sam Baines
4,315 Points

HI Tomasz - A couple of things, like the answers above you have the typo but also there are a couple more errors in your code. Firstly at the bottom you use a second Console.ReadLine(); which is not necessary. Secondly the challenge is meant to put to use the C# components you have learnt during the course - a for loop is not one of these, so this might be better if you swap out with a While Loop - I know this works as I have only just completed this challenge today with the following code:

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the number of times to print \"Yay!\": ");
            var entry = int.Parse(Console.ReadLine())
            var x = 0;

            while (true) {

                if (x < entry) {
                    Console.Write("Yay!");
                    x++;
                }
                else
                {
                    break;
                }
            }

        }
    }
}
Tomasz Sporys
Tomasz Sporys
11,258 Points

Thanks a lot all of you guys. I would pick all of you as best answers if I could :) In my opinion Threehouse should be more flexible regarding strings like "Yay" or whatever :) BTW I didn't realize there wasn't for loop in this course. :) I treat it like a refresh :)

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

Hi there! You have a typo. It's supposed to be "Yay!", but you're printing out "Yey!". When checking strings challenges often require that they be exactly the same to the letter. Try this:

Console.WriteLine("Yay!");

Hope this helps!

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Tomasz,

Yes, your code is correct syntactically, but there is a small variation you have from what the Treehouse challenge asked for. The challenges here are very picky and very strict (in order for the code checker to work property).

The challenge wants "Yay!" printed (with an "a"), but you have "Yey!" (with an "e"). Just fix that up and you're good to go.

Keep Coding! :) :dizzy: