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 trialLive Top
3,916 PointsRandom number js - it works but could i have done better?
Hi guy, great to be here. TeamTreeHouse rocks! :)
I would love to here a quick review from the more experienced programmers about how i did in this task.
The idea is to store a number from a user input, then to print a random number from 1 to that number. pa: It was quite a struggle to avoid getting a zero
Any quick review? thx :)
var userInput = parseInt(prompt('Please write a number'));
var userInputFinal = userInput + 1;
var one = 1;
var whatever = Math.ceil(Math.random() * (userInputFinal - one ));
document.write(whatever);
2 Answers
Matthew Mariner
17,666 PointsWhen it comes to comparing to other code, I would advise going ahead and giving StackOverFlow a quick search for your criteria. There's some good questions surrounding some core concepts of the JS language on there that will help you code better, especially using math.rand and parse.ints
Live Top
3,916 Pointsgreat, will do that, thanx :)