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

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

The code is working, not sure why you say it's not.

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

Works fine in the console

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.