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

weird browser reaction.

var dice = {
  sides: 6,
  roll: function () {
    var sides = 6;
    var randomNumber = Math.floor(Math.random() * dice.sides) + 1;
    console.log(randomNumber);
  }
}```

When i go into a console and type in dice.roll. the console gives me "function dice.roll()" and no random number

1 Answer

Hey Ivan,

You have to call the roll method... like this:

dice.roll();

does it suppose to give me an undefined line right after the random number?

Yup. It's because you didn't return anything from your function. Every function has a return method that's set to undefined by default. If you return the value of randomNumber, (as opposed to console.log(randomNumber)) the console will just show the random number.

Thanks Mikis, JavaScript is a little weirder for me, so I am having a little bit of "what a hell you doing" issues with the console :-)