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 trial

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

Full Stack JavaScript Techdegree Student 890 Points

Hello everyone here is my code. Any pointers would be great.

alert('This is a random number generator. You pick the start number and the end number........And go');

var randomNum = prompt('What is your starting number?');

var randomNum2 = prompt('What is your 2nd number?');

var convert = parseInt(randomNum);

var convert = parseInt(randomNum2);

var random = Math.floor(Math.random() * randomNum2);+ randomNum alert ('Your random number is ' + random );

Greg Lawrence
Greg Lawrence
7,960 Points

I realize this is an old thread, but no one responded. Overall, you seem to be on the right track. I did notice a couple errors in your code.

You have two variables named the exact same name. (convert).

I think you should re-code those lines like this:

randomNum = parseInt(randomNum);
randomNum2 = parseInt(randomNum2);

Then your line starting with var random seems to have an error near the end in where you placed the ; and I think the algorithm for a range is incorrect.

try this:

var random = Math.floor(Math.random() * (randomNum2 - randomNum + 1) + randomNum);

You can read about the many methods to generate a random number in a range at MDN here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random