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

JavaScript JavaScript Basics (Retired) Working With Numbers The Random Challenge

Solution-Feedback. Thanks

var collectNumber = prompt('Please pick a number')

var collectNumber2 = prompt('Please choose second number')

var collectRealNumber = parseInt(collectNumber);

var collectRealNumber2 = parseInt(collectNumber2);

var collectNumberMin = Math.min( collectRealNumber, collectNumber2 );

var collectNumberMax = Math.max ( collectNumber, collectNumber2 );

var randomNumber = Math.floor(Math.random() * (collectNumberMax - collectNumberMin + 1)) + collectNumberMin;


2 Answers

Steven Parker
Steven Parker
228,026 Points

Making the numbers order-independent was a nice touch. :+1:

And for future code postings, use Markdown formatting to preserve your code appearance.

Jamie Reardon
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

+1 to Steven's answer! Also since your asking for feedback, you could clean up your code a little by deleting the two "RealNumber" variables by using the parseInt method on the original variables that contain the string input.

var collectNumber = parseInt( prompt('Please pick a number') );

var collectNumber2 = parseInt( prompt('Please choose second number') );

Using less global variables means less memory needed to hold this data in the browser, which is a plus in performance. Also, you are missing a couple of semi-colons. Nothing major of course, but something to get into the habit of!

Nice work!