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 trialCuciureanu Dragos
5,916 PointsWhy we create 2 dice , dice(6) and dice(10)?
Why we create 2 dice , dice(6) and dice(10) , but when we press on dice it gives us number form 1 to 6? so what is the roll of dice(10)? Why the prototype take the 6 and not 10? :D i can't undestand this.
1 Answer
John Coolidge
12,614 PointsCuciureanu,
If you open the console, you'll see why there's a Dice(6) and a Dice(10).
What Andrew is showing you is whether or not these two instances of the constructor function are the same. They are the same in both value and type (hence the triple equals sign). The console logs the boolean value, in this case, true. You don't need the second instance, that is, Dice(10), for any other reason then that. If you were building a program much like the example, you would only need one instance of the constructor function if you were only going to display a single dice roll, as shown in the HTML.
If you have any other questions, feel free to ask!
John
Cuciureanu Dragos
5,916 PointsCuciureanu Dragos
5,916 PointsRight now i understand :D, i take a loock into ui.js folder so i undestand why it prints just the first value because there we have result = dice.roll(); so its 6. First time i thought the prototype make something like a default value and all the time when we create a new dice it will give us just the first dice. But now i understand how it works :D! Thak you for the answer and for the help :D!