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

Gary Calhoun
Gary Calhoun
10,317 Points

Is this correct?

Hi was just trying to see if I did this correctly.

function getRandomNumber(upper, lower){
  var randomNumber = Math.floor(Math.random() * (6 - upper + lower)) + 1;
  return randomNumber;
}

document.write(getRandomNumber(10, 100));

3 Answers

no, but close. it would be easier to trim that up a bit.

try this:

var getRandomNumber = function(upper, lower){
    return Math.floor(Math.random() * (6 - upper + lower )) + 1;
};

document.write(getRandomNumber(10, 100));

what you had wouldn't have worked, because you defined your function as a variable like so:

var getRandomNumber(upper, lower) = ......

but you cannot place arguments into the definition of a variable. If you had defined it like so:

var getRandomNumber = function(upper, lower) {....}...

that would have been correct.

You were sooo close! just keep an eye on the little things like that and you'll go very far. :)

Gary Calhoun
Gary Calhoun
10,317 Points

Ahh I see what you mean, thanks again either way I just gained a level:)