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 Solution

I did it differently but will it still work the same way?

var rndNum = parseInt(prompt("Write a number (any)")); var rndNumTwo = parseInt(prompt("Write a number larger than the number you wrote before.")) var showNum = Math.floor(Math.random(rndNum) * rndNumTwo); alert(showNum);

1 Answer

Steven Parker
Steven Parker
222,348 Points

The program in the video will generate a number between (inclusive) the two numbers entered. But the different formula will get different results.

This one will generate a number from 0 up to (but not including) the second number. The first number is ignored entirely because the "random" function does not take an argument.

Oh ok thank you! :)