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 trialAakash 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
231,275 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
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