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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Aakash Srivastav](https://secure.gravatar.com/avatar/67d42ff92ed9bcb21fe7cabeb710965c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Pointswhile loop
Please review my code. I have tried a different approach . I give the independency to user to choose the "upper" limit. -
function getRandomNumber(upper){
var counter = 0;
while( counter < 100){
randomNumber = Math.floor(Math.random() * upper + 1);
document.write(randomNumber + " ");
counter += 1;
}
}
getRandomNumber(15);
Is there any limitation to this approach ?
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI'm not sure what some of Matthew's comments are based on, in particular:
- the parameter name is fine as is
- your method of incrementing "counter" is already the recommended "best practice"
For pure cosmetics, removing the space in the "while" expression is good, but it would also be nice to add a space after "while" and also before the braces that start code blocks.
Functionally, the code is excellent, I can't think of any limitations. Good job!
![Aakash Srivastav](https://secure.gravatar.com/avatar/67d42ff92ed9bcb21fe7cabeb710965c?s=60&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsIt feels good to be appreciated by such a great Teacher . It brings too much motivation . Thanks Steven :)
Mathew Tran
Courses Plus Student 10,205 PointsMathew Tran
Courses Plus Student 10,205 PointsIn terms of limitations, I'd say it depends what you are going to use this code for, it seems sufficient enough for this lesson :)
Matt