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 trialTetsuya Yokoyama
11,286 PointsWhy are we making the creater method createPlayers()?
Since the method createPlayers() only set and return an array, isn't it possible to just do like this below?
constructor() {
this.players = [new Player("Player1", 1,"#e15258", true),
new Player("Player2", 2, "#e59a13")];
this.board = new Board();
this.ready = false;
}
I don't understand why we need to make that simple method, because the number of players is already fixed. Or is it just break it down for covering the case when we wanna make change to the number of players flexible?
2 Answers
Steven Parker
231,271 PointsTechnically, it would work just as well your way. I think the idea was just to show a modular and flexible approach.
Eugene Dianov
4,264 PointsBecause there is a good principle - a single responsibilities principle. Each method should be responsible only for one piece of functionality.