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

I don't know why my code is not generating random number in the console.log

I am learning about JavaScript object. I created an object literal. For some reason, my console.log is not generating random number. I personally don't see any bug in my code. I guess it might be chrome.

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

 }

2 Answers

Your code is working for me. What are you typing in the console to call the method?

dice.roll() // This works for me using Firefox.

yes, rydavim. I am using dice.roll()

Just checked it with Safari, and it works there too. Sorry, sounds like it might be a Chrome issue!

weird. Works for me on Chrome with Windows.

ok, thanks all.