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

Rui Neves
Rui Neves
3,393 Points

Check my code out! Thanks! :)

//collect 2 numbers and generate a number between those 2

var numOne = prompt("Write one number between 1 and 10"); //Collect a String.

var numTwo = prompt("Write one number between 10 and 20");//Collect a String.

alert("I will generate a number between " + numOne +" and " + numTwo)//Alert out which Strings(Numbers) where chosen.

var parseNum = Math.floor(Math.random() * (parseInt(numTwo) - parseInt(numOne)) + parseInt(numOne));

//Execute the substration between parseInt2 and parseInt1 add the parseInt1 and creates a random number between the 2 from the user.

console.log(parseNum); //Log out to the console the random number.

alert(parseNum); //Alert out the random number!