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 trialchristian rylander
4,609 PointsHow do I type a string as many times as the users number?
I need help with this challenge
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
}
}
}
3 Answers
Pablo Rocha
10,142 PointsI won't give you the exact answer, but what you are supposed to do is use a for loop.
Take the number the user inputs and use it to loop that many times. During each loop print yay!
for (int i = 0; i < userInput; i++)
{
// Print out yay!
}
Steven Parker
231,236 PointsThere's a few steps to this:
- Input the user's response.
- Convert the response to a number
- Use the number as a loop counter
- Inside the loop, print the message
You've done all these things in previous challenges, here you just put them all together.
christian rylander
4,609 Pointshow do I use a number as a loop counter?
Karen Freeman-Smith
29,248 PointsYou can read the number that is entered and assign it to a variable. Then use that variable to control a loop that prints "Yay!" to the console. You might want to rewatch the video if that sounds confusing, or ask a more specific question about the code you are trying to get to work.
christian rylander
4,609 Pointschristian rylander
4,609 Pointsok thanks!