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

Tell us what’s happening:

not understanding why this isn’t working =>
Inside the filter method, add a callback function with a parameter called player and implicitly return player.nickname is not null

This is the error I’m getting =>
Your filter() callback should implicitly return the result of checking if player.nickname is not null .

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

switch (e.target.value) {
    case "nickname":
    setPlayerCards(players.filter((player) => {
      player.nickname != null ? player.nickname : player
    }))
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

You don’t need to use a ternary expression here. Only implicitly return player.nickname is not null. Also, delete the curly braces.

2 Likes

thank you, i’ve been stuck on this for a while

1 Like

would the same apply for this one?

Next, add a case clause for forward.

Inside that case, call the setPlayerCards function with an argument of players.filter().

Inside the filter() method, add a callback function with a parameter of player that will check if player.position equals forward.

Lastly, add a break statement below the setPlayerCards function call.

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

error message => Your filter() callback should implicitly return the result of checking if player.position is forward .

This actually passed for me

    setPlayerCards(players.filter(player => player.nickname !== null))

1 Like

I have the same thing but it’s also not passing the test:
case “forward”:
setPlayerCards(players.filter((player) => player.position === forward));
break;

Ok…solved it…I won’t say how exactly, but it has to do with punctuation. :slight_smile:

use only two not three equal signs