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 Solution

Zack White
Zack White
1,387 Points

this wont work for some reason

function getNumber (lower, upper) { return Math.floor(Math.random () * (upper - lower + 1 )) + lower; }

console.log(getNumber(23,9));

6 Answers

Seth Kroger
Seth Kroger
56,413 Points

The way you've defined the function, the lower number is supposed to come first, then the upper. So you should be writing console.log(getNumber(9, 23));

Zack White
Zack White
1,387 Points

unfortunately that didn't change anything...

Steven Parker
Steven Parker
231,248 Points

It seems to work great once you put the parameters in the right order. What makes you think it's not?

Zack White
Zack White
1,387 Points

its not showing random numbers in my console

Zack White
Zack White
1,387 Points

ok so I tried firefox and it worked.... thanks!!!

Zack White
Zack White
1,387 Points

This is annoying. It only shows one result

function getNumber (lower, upper) { return Math.floor(Math.random () * (upper - lower + 1 )) + lower; }

document.write(getNumber(9,23)); document.write(getNumber(5,42)); document.write(getNumber(1,2421)); document.write(getNumber(25, 5));