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

Larissa Röhrig
Larissa Röhrig
1,787 Points

What's wrong with my code?

There is no error but my code isn't working.

function getRandom ( upper, lower ) {
return Math.floor(Math.random() * (upper - lower + 1)) + lower; 
  }
console.log( getRandom(30,40) );
console.log ( getRandom(100,300) );

I don't see anything wrong, and it worked fine in my browser...

3 Answers

Larissa Röhrig
Larissa Röhrig
1,787 Points

I don't know why but it didn't work in my console...

Erik Nuber
Erik Nuber
20,629 Points

Works fine in the console

Larissa Röhrig
Larissa Röhrig
1,787 Points

I don't know why but it didn't work in my console...

Your code didn't work for me in Safari 11.1.2 with javascript enabled in Safari Preferences. Nor did my own code. Alerts work fine, but not console.log. Had same problem with Chrome. Sorry, I have no answer as to why.