Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
215,939 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?