Parameters in the player cards assignment

So im doing the player cards assignment with javascript right now and need to clear something for my understanding.
i have an object called players that holds the name, position and nickname etc for the players.

In my switch-case, where i am filtering through that object i am using a parameter called player (not an s in the end). I am CONFUSED by this, because player is not defined anywhere in my code as i can see, if it was players i would get it. Would love if someone would explain this to me as it seems stupid to carry on without knowing what the parameter does there.

so object is called players
in my switch : case “forward”:
setPlayerCards(players.filter((player)=>player.position===“forward”))

would love to get some clarity on this.

The property value of the case statement “forward” is the calling of the function setPlayerCards. Within the parameter of that function there is a call back function. Within the parameter of that call back function is “player” . That represents the value of the player when the call-back function is called. The value passed will represent the player selected in the drop down box. The parameter is a type of variable and so the name of that variable is a placeholder representing the value that gets passed to the function when it is called.

Thanks alot! Just for deeper understanding. if i DIDNT have player to act as a placeholder, what would or wouldnt happen?

if you do not have a parameter in the callback function, you can’t reference each element of the array

1 Like

hi again! i think i finally had that moment when i finally understood parameters . i made a function to remove all special characters.

const removeSpecialChars=(string)=>{
return (string.replace(/[a-zA-Z0-9]/g “”));

and then i applied this inside my taskObj like:

title: removeSpecialChars(titleInput.value).

SO, whats inside the parenthesis there is now acting as the value of the string parameter in the function? so string is just a word that holds the titleInput.value in that case?

yes, the parameters will get a value when the function is called with arguments, in this case string takes the value of titleInput.value

lovely! Thanks a lot

Great - it was worth taking the extra time to understand functions and parameters. It’s hard to make progress without nailing those. Good luck in the rest of your journey.

absolutely! for me some things just cant be understood unless i can see the connections for myself in real time and then it finally just clicks. Was just kind of waiting for it to happen with parameters as i go along . Will definately ask more “stupid” questions here now since i got such nice response.

1 Like