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

Jamilur Rahman
Jamilur Rahman
3,336 Points

My Code works really well. Can someone check out my code to see why it is so different the video solution?

var input = prompt('What is the first number'); var input1 = prompt('What is the end number');

var firstNum = parseInt(input); var endNum = parseInt(input1);

var roll = Math.floor((Math.random()*endNum) + firstNum ); var message = "<p>" + roll + " is a number between " + firstNum+ " and " + endNum + ".</p>"; document.write(message);

alert(roll);

Hi there, what video are you referring to ? be sure to create questions from video lessons page.

Jamilur Rahman
Jamilur Rahman
3,336 Points

It is not really a question. It is a coding challenge for java script. they want me to ask for first num and second num. then make it into a range. i just wanted to know if it elogic for my var roll is correct

1 Answer

Steven Parker
Steven Parker
216,057 Points

The formula shown here is likely to generate a number well outside the requested range. For example, try asking it for a number between 1000 and 1010.

The classic formula (adapted to these variable names) would be:
ā€ƒ Math.floor((Math.random() * (endNum - firstNum + 1)) + firstNum;