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
Ivan Marchenko
8,962 Pointsweird browser reaction.
var dice = {
sides: 6,
roll: function () {
var sides = 6;
var randomNumber = Math.floor(Math.random() * dice.sides) + 1;
console.log(randomNumber);
}
}```
1 Answer
miikis
44,957 PointsHey Ivan,
You have to call the roll method... like this:
dice.roll();
Ivan Marchenko
8,962 Pointsdoes it suppose to give me an undefined line right after the random number?
miikis
44,957 PointsYup. 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.
Ivan Marchenko
8,962 PointsThanks 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 :-)
Ivan Marchenko
8,962 PointsIvan Marchenko
8,962 PointsWhen i go into a console and type in dice.roll. the console gives me "function dice.roll()" and no random number