Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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 :)