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) Creating Reusable Code with Functions Random Number Challenge

Is there such a thing as a wrong execution..?

Below is my code. It seemed to do exactly what his did but looks nothing like it. Am I wrong or just not efficient enough yet?

function randomNumber(number1, number2) { return number1, number2; }

var one = (Math.floor(Math.random() * (30000 - 1 + 1)) + 1); var two = (Math.floor(Math.random() * (400000 - 1 + 1)) + 1);

alert(randomNumber(one, two));

1 Answer

Steven Parker
Steven Parker
231,248 Points

You've created the same end result but with code having a different intent.

The intention of the code in the video is to create a function that will return a random number, and then use that function in the body of the code.

But you created a function that only reflects one of it's arguments, and created a random number in the body of the code which you passed through the function (you actually created two, but one of them is simply discarded).

So while the final output may seem the same, what the programs actually do is very different. This would become apparent if the program were to be extended with additional code that called the same function and expected it to return a random number in the provided range.