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

Chris Murphy
Chris Murphy
4,391 Points

Code Challenge Error bug?

I'm getting an error that says catch is on line 39-is this a bug and the reason my code isn't working? And I'm not sure why the curly brackets are unexpected...

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            bool keepGoing = true;

            while (keepGoing == true)
            {
                //Prompt user for number of 'Yays'
                Console.Write("Enter the number of times to print \"Yay!\": ");
                string entry = Console.ReadLine();

                if (entry.ToLower() == "quit")
                {
                    keepGoing = false;
                }
                else
                {
                    try
                    {
                        var numberYays = int.Parse(entry);

                        if (numberYays <= 0)
                        {
                            Console.WriteLine(numberYays + " is not an acceptable value.");
                            continue;
                        }
                        else if (numberYays > 25)
                        {
                            Console.WriteLine(numberYays + " are too many \"Yay!'s\" for one day.");
                            continue;
                        }
                        else 
                        {
                           Console.WriteLine (String.Concat(Enumberable.Repeat("Yay! ", numberYaysy))); 
                        }
                    catch (FormatException)
                    {
                        Console.WriteLine("That is not valid input.");
                        continue;
                    }



                    }
                    //Repeat until user quits
                }

                Console.WriteLine("Goodbye");
            }


        }
    }
}

2 Answers

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

Here's a couple of things to note. They haven't covered Enumerations yet and you aren't using System.Linq. Also your try block is missing a closing curly braces at the end. Keep in mind that they explicitly ask you to use a loop to print out the number of "Yays!". If you need more assistance, let us know! :sparkles:

edited for additional note

There's also a misspelling of your variable name on this line:

Console.WriteLine (String.Concat(Enumberable.Repeat("Yay! ", numberYaysy)));
David Good
David Good
12,348 Points

Just a suggestion, download visual studio and paste your code in there. It will give you hints where your code is invalid or has little mistakes