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: Challenge Building Constructor Methods and Generating Objects Game Class Constructor Method Solution

Can my solution work?

I was thinking that my solution was correct until I saw Ashley's solution which is totally diferent than mine.. Now I feel discourage :(

I created 2 objects with their attributes... : createPlayers(){

  var player1 = {
    name: 'Player 1',
    color: '#e15258',
    id : 1,
    active: true

  var player2 = {
    name: 'Player 2',
    color: '#e59a13',
    id : 2,
    active: true

2 Answers

In your solution, you create object literals but you should create using the Player class to create a Player object.

Ashley uses the Player class passing in the arguments the Player constructor takes, whereas in your solution you do not use the Player class, therefore, are not using the power of Object Oriented Programming.

Ian Ostrom
Ian Ostrom
Full Stack JavaScript Techdegree Student 10,331 Points

raul montes Don't feel bad. It is OK to create objects individually like you have, it just makes the Player class unnecessary. To build on what Liam said, OO programming saves us time as a developer when doing things at larger scales. If you were going to create 100 copies of an object, it would be far more efficient to use a class and a perhaps a loop of some sort like we did in the Player and Board classes to create the tokens and spaces.