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.

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

My solution is good?


Here is my solution. Is it good?

 /* First Generator */

var ask = prompt("Tell a number please:"); 
var number = parseInt(ask);
var result = Math.floor(Math.random()*number)+1;
document.write("The" + " " + "number" + " " + "is" + " " + result + "<br /><br />" );

/* Second Generator */

var num = prompt("Tell a number please:");
var int = parseInt(num);
var num2 = prompt("Tell an other number please:");
var int2 = parseInt(num2);
var result2 =Math.floor(Math.random() * (int2-int))+int;
document.write("The" + " " + "number" + " " + "is" + " " + result2);

2 Answers

Hi Adam,

Working solutions are always good solutions. Nice job figuring out how to generate a random number from two user inputs!

One thing I noticed that might help to make it easier on you is to modify the document.write lines without concatenating spaces unnecessarily. Spaces can be part of a continuous string.

document.write("The number is " + result + "<br /><br />" );

Thanks for sharing!


Hi Robert,

thanks for help.

Cheers :)