Find a Player
JavaScript
10 pts
Find a Player
Write a function findPlayer(list, name) that uses indexOf():
- If the name is in the list, return
"Merhawi is number 3"— the position counted from 1 (index + 1). - If not, return
"Ruta is not in the team"(with the given name).
The starter prints two searches:
Merhawi is number 3 Ruta is not in the team
Checklist
- Return the position (from 1) when the player is in the list.
- Return the “not in the team” message when the player is missing.
- Use
indexOf(). - The two 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.
