Teams and game lesson remix and wonderings (Javascript lesson)

greetings!
I was wondering why the factory function outside of an object would be/ is it bad to do in practice?
I feel that i would be able to understand that syntax a little easier down the line and would save me having to write out the branch to the key each time i wanted to add a new object to an array. in fact i bet i could even make this factory function account for where to put things if I added an additional parameter that switched where the object would go in the first parameter.

so then i tried to do both what the lesson was telling me to do and what i wanted to do at the same time to see if it would break anything… but it seems like there would be no problem? Soooo is it bad practice to have a fact function outside of an object that alters an it rather write it inside as a method???

here’s where i stopped

const team = { _players: [], _games: [], get players() { return this._players; }, get games() { return this._games; }, addPlayer(firstName, lastName, age) { return this._players.push({ firstName, lastName, age }); }, addGame(opponent, teamPoints, opponentPoints) { return this._games.push({ opponent, teamPoints, opponentPoints }); }, }; //add methods via the lesson team.addPlayer("Bugs", "Bunny", 76); team.addGame("Titans", 100, 98); // factfunc: add playerObj to the playLIST let newPlayerOnTeam = (firstName, lastName, age) => { return team._players.push({ firstName, lastName, age }); }; //add your players below newPlayerOnTeam("Cloud", "Strife", 77); newPlayerOnTeam("Squall", "Lionheart", 88); newPlayerOnTeam("The", "Lich", 99); //factfunc:add a gameObj to Game List let newGame = (opponent, teamPoints, opponentPoints) => { return team._game.push({ opponent, teamPoints, opponentPoints }); }; //add your games below //log check console.log(team.players); console.log(team.games);

You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility

When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!

If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer! :slight_smile: