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 trialMars Epaecap
5,110 PointsWhen I put dice.roll() into the console I get "Uncaught ReferenceError: dice is not defined(…)"
When I put dice.roll() into the console I get "Uncaught ReferenceError: dice is not defined(…)"
I get this with
var dice = {
roll: function diceRoll() {
var sides = 6;
var randomNumber = Math.floor(Math.random() * sides) + 1;
console.log(randomNumber);
}
};
and
var dice = {
roll: function {
var sides = 6;
var randomNumber = Math.floor(Math.random() * sides) + 1;
console.log(randomNumber);
}
};
ywang04
6,762 PointsThe second one should be:
var dice = {
roll: function () {
var sides = 6;
var randomNumber = Math.floor(Math.random() * sides) + 1;
console.log(randomNumber);
}
}
() is missing after function key word.
5 Answers
Van Jayson Pelayo
5,263 PointsCheck if your linking your javascript file correctly to your html.
Christian Hals
11,811 PointsAre you using Chrome?
I had the same problem with this project and I´m able to reproduce it every time by doing the following:
Loading the page, open the console and typing dice.roll() into the command line. I then get the "Uncaught RefrenceError: dice is not defined(...) It seems the page doesn´t load properly on the first attempt (every time for me in Chrome), in Safari however the problem is not present.
I then hit refresh in the browser, type dice.roll() and voila it works:
dice.roll()
VM1843:1 Uncaught ReferenceError: dice is not defined(…)(anonymous function) @ VM1843:1
Navigated to http://127.0.0.1:51396/index.html
dice.roll()
dice.js:5 4
undefined
´´´
Sean Walcott
Courses Plus Student 5,506 PointsI'm having the same problem on chrome and firefox, dice.roll just calls the function and doesn't run it.
Jared Fuller
12,511 PointsSean, I was having that problem, and then I saw he did dice.roll() not just dice.roll and that solved it for me on Chrome.
Tim Pinkerton
23,019 PointsI was getting the same error. In the console, he says to type "dice.roll()", but the function is "diceRoll()" without the . after dice. It worked for me when I used "diceRoll()".
Idelle Diaz
8,591 PointsI had the same error on Firefox and Safari. I realized that I didn't have the log tab clicked and it was only showing me the errors/warnings in the code and not what was printed to the log.
Cristen Hewett
23,811 PointsThank you Idelle! That was the exact issue I was having...in Chrome. I ahd "Filter -> Errors" on...and didn't have "info" selected.
Quantarius Ray
Full Stack JavaScript Techdegree Student 4,403 PointsQuantarius Ray
Full Stack JavaScript Techdegree Student 4,403 PointsWell at least on the second one you did function without executing it. dice= { roll: function() {} }