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
Abe Layee
8,378 PointsI 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
rydavim
18,814 PointsYour code is working for me. What are you typing in the console to call the method?
dice.roll() // This works for me using Firefox.
Abe Layee
8,378 Pointsok, thanks all.
Abe Layee
8,378 PointsAbe Layee
8,378 Pointsyes, rydavim. I am using dice.roll()
rydavim
18,814 Pointsrydavim
18,814 PointsJust checked it with Safari, and it works there too. Sorry, sounds like it might be a Chrome issue!
Andrew McCormick
17,730 PointsAndrew McCormick
17,730 Pointsweird. Works for me on Chrome with Windows.