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!

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


Live Top
Live Top
3,916 Points

Random 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 ));


2 Answers

Matthew Mariner
Matthew Mariner
17,666 Points

When 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
Live Top
3,916 Points

great, will do that, thanx :)