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

issa Mohamed
issa Mohamed
7,373 Points

would this work

class Game { constructor() { this.board = new Board; this.ready = false; this.players = createPlayers(); } /**

  • Creates two player objects
  • @return {Array} An array of two Player objects. */ createPlayers() { let p1 = new Player('player1', 1, '#e15258', true); let p2 = new Player('player2', 2, '#e59a13',); playersarr = [p1,p2] return playersarr } }

1 Answer

Steven Parker
Steven Parker
231,236 Points

There's rarely only one way to do something in programming, and this is a good example.

But why not try it in your workspace and see if it works firsthand?