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 trialRich P
2,356 PointsDoes This Still Work?
I copied the code exactly and this would only return the result of 1. I even launched the completed workspace by the instructor and previewed that code which had the same problem. I opened the URL in a private browser window in case it was a cache issue and it still won't work. Am I the only one experiencing this problem?
3 Answers
Prath M
9,631 PointsThe ui.js file in this Workspace does not reflect the update to the var result for the button.onclick method. Change it to var result = dice.roll(); and the code given by Andrew will work.
Maxwell Kendall
Front End Web Development Techdegree Student 12,102 Pointswhy is this? when you call a property that holds a method in an object... it should work without using the ()? Right?!
Chad Donohue
5,657 PointsCould you post the code that you have?
vijay bhaskar
3,893 PointsThis worked for me
Dice.js:
function Dice(sides){
this.sides = sides;
this.roll = function () {
var randomNumber = Math.floor(Math.random() * this.sides) + 1;
return randomNumber;
}
}
ui.js: Call this method on click of button printNumber(dice.roll());
Jeffrey Eng
2,555 PointsJeffrey Eng
2,555 PointsI have the same issue too. I wrote the code exactly as the instructor did, then ran it in my browser. I clicked the roll button and it only returns 1.