Team Manager
JavaScript
20 pts
Team Manager
Write three functions for the five-a-side team of Keren FC. Each gets the team array as its first parameter:
addPlayer(team, name)adds the name at the end, but only if the team has fewer than 5 players. It returns the team’s length afterwards.benchPlayer(team, index)removes the player at that index withsplice()and returns the removed name (a string, not an array).teamSheet(team)returns the names joined with" | ".
The starter tries to add three players to a team of three (the last one does not fit), benches index 1 and prints:
Abel | Yonas | Merhawi | Senait | Ruta Bench: Yonas Abel | Merhawi | Senait | Ruta
Checklist
- Write
addPlayer(team, name)with the 5-player limit. - Write
benchPlayer(team, index)withsplice(). - Write
teamSheet(team). - The three lines are printed.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
