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 trialTomasz Sporys
11,258 PointsFunny that it works in Visual Studio but not in "Treehouse Studio":(
What's up folks? How is this code wrong?
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();
}
}
}
3 Answers
Sam Baines
4,315 PointsHI 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
11,258 PointsThanks 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
Treehouse TeacherHi 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
Treehouse Moderator 145,860 PointsHey 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! :)
Hendrik Heim
1,012 PointsHendrik Heim
1,012 Pointsinstead of var try int.
It's a compiler issue I guess.
EDIT: or just the "Yay" :P