Learn Modern JavaScript Methods by Building Football Team Cards - Step 41

Tell us what’s happening:

I tried a ternary for this question because it seems thats the way to check if at this point, but the !== was suggested to be used for this, and it still doesn’t seem to work…

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

case "forward":
  setPlayerCards(players.filter((player => player.position !== "forward")));



// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Learn Modern JavaScript Methods by Building Football Team Cards - Step 41

if you use !== you remove the players with the forward position, instead you want to keep those

after that, you have too many parenthesis around the callback function

after that, follow the hints to conclude

so don’t use !==?

in this case you want to keep the players that have a position of forward, so you don’t use !==

the other time you need to remove the players where nickname was null, so you used !==

but this doesn’t work either:

case "forward":
  setPlayerCards(players.filter((player => player.position ? "forward": "")));

reminder on how filter works:
filter works that it keeps the values for which the callback function returns true and removes the values for which the callback function returns false, so depending on what you need you could use a comparison with !==, but not always

you are using a ternary, and as player.position is a truthy value, the ternary would always give back "forward", which is truthy, which means filter is keeping all of the items in the array.

I don’t think that the ternary is needed here

you need an expression that returns true when player.position is "forward" and false otherwise

so what expression is to be used…

I can’t write it for you.
What was the issue with the expression you where using?

that it returns false when player.position is false, right? and you want the opposite. Can you make a small change to this so that it works as you need?

check if player.position is equals to "forward".

like this?:

case "forward":
  setPlayerCards(players.filter((player => 
  if(player.position === forward){
    
  }  )));
break;

You didn’t need to add an if statement. Also you have removed the quote marks around "forward", and have extra parentheses and braces.

like this?

case "forward":
  setPlayerCards(players.filter((player => {player.position === forward} )));
break;

your function now returns undefined, because you are not using implitic return anymore
also, forward should be a string, you don’t have a variable of that name
and you have extra parentheses

like this?

case "forward":
  setPlayerCards(players.filter((player => {player.position === "forward"} )));
break;

you have fixed only one of the three things I pointed out, you still need to fix the other two

Not sure if I can see any extra parentheses, they all seem to have a corresponding parentheses, which parentheses did you have in mind?

the two consecutive (( that have two corresponding ))
one of them is extra

Then this should work?:

case "forward":
  setPlayerCards(players.filter(player => {player.position === "forward"} ));
break;

you still need to fix the third thing

so how do you make that an implicit return