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 trialLarry (Bo) Arrington
Courses Plus Student 3,787 PointsNeed assistance on final challenge #2
Can not seem to get program to compile. Not sure where to start so asking for any assistance. Thanks/Larry
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
{
Console.Write("Enter the number of times to print \"Yay!\": ");
int userValue = int.Parse(Console.ReadLine());
try
{
if (userValue.getType() == "integer")
{
int i;
for (i = 1; i < userValue; i++)
Console.WriteLine("Yay!");
break;
}
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
4 Answers
Robert McNeil
6,466 PointsYou were pretty close. dont worry about the tes for integer.
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
try{
int userValue = int.Parse(Console.ReadLine());
if(userValue < 0) {
Console.WriteLine("You must enter a positive number");
} else{
for (int i = 0; i < userValue; i++){
Console.WriteLine("Yay!");
}
}
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
}
}
}
}
Robert McNeil
6,466 PointsTruth is everything you needed was in the previous videos. Sometimes the questions they ask durring the challenges dont speak at the same level so they can be tough for a beginer to understand what exactly they are asking for. Ive had the same problem.
The challenges are broken down into simple steps, usually at least. Try to figure out the question first, then use what you learned recently to pass the challenge.
When compiling code in a challenge also use the response as a means to figure out what may have gone wrong. Also look at the output of the comiler by clicking on the "preview" button, this will give you the output of the compiler. This can be helpful in fixing your errors. Learning to use your compiler output is a skill you must master at some point.
Also consider building your code a small piece at a time, runnig it, checking the compiler output then fixing it or adding more. Its an ok way to learn if you arent that confident in your code.
Regardless, goodluck!
Larry (Bo) Arrington
Courses Plus Student 3,787 PointsI was able to use your insights and get through several other challenges and exercises. I appreciate your honesty and this helps give me and increased level of confidence to continue through upcoming obstacles.
Robert McNeil
6,466 PointsYeah, I can understand your apprehension. I do similar things when it comes to learning new stuff. There are some small tricks that arent taught in the classes that could be very helpful. Keep posting your questions, someone will help.
Larry (Bo) Arrington
Courses Plus Student 3,787 PointsLarry (Bo) Arrington
Courses Plus Student 3,787 PointsThanks Robert for the response and the coaching - it really helps when you are first starting out.