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

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.