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 trialPerry Triekens
685 PointsSomething wrong with my code
Treehouse keep saying "Try again!". There no errors in my code.
Someone who knows what i did wrong?
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
var entry = Console.ReadLine();
try
{
var times = int.Parse(entry);
int i = 0;
while (true)
{
i += 1;
Console.WriteLine("Yay!");
if (i == times)
{
break;
}
}
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
}
}
}
}
2 Answers
Henrique Vignon
Courses Plus Student 6,415 PointsHmmm, indeed there's nothing wrong with it, it would work just fine, but perhaps the challenge is actually expecting you to use a for loop? (in fact that would be the best loop to use in this situation, even though using while works too)
Perry Triekens
685 PointsThanks for the response. I had to make a for loop.
Henrique Vignon
Courses Plus Student 6,415 PointsHenrique Vignon
Courses Plus Student 6,415 PointsI just checked the challenge and passed using for, just to be sure you're still in step 2 right? because step 3 asks for something you haven't done in your code, to check if the number entered is negative or not.