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 Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Challenge Solution

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

Code written exactly like in the video and it still doesn't work?

function DiceRoll(side) { this.sides= side; this.roll=function(){ var randomNumber = Math.floor(Math.random() * this.sides) + 1; return randomNumber; }; //end random number function }; //end dice function

var dice= new DiceRoll(6);

1 Answer

Steven Parker
Steven Parker
229,785 Points

The "roll" function works great! :+1: But perhaps you're talking about what happens when you press the "roll dice" button on the screen? That's a result of what's on line 9 of "ui.js":

  var result = 1;

As you can see, it will always show a "1". But if you wanted to show a dice roll instead, you could replace that line:

  var result = dice.roll();

Great idea to post the snapshot, it made it simple to find the issue even though it was in different code.

I had the same problem. Thx a lot Steven Parker !