JavaScript Football Team Cards Step 41

Exercise Description
Step 41

Call the setPlayerCards function with an argument of players.filter().

Inside the filter method, add a callback function with a parameter called player and implicitly return player.nickname is not null.

Code I am attempting to submit


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

I have the parameter as player and my object shows “not null”
Do i need to explicitly say return?

I have tried a few variations and with the “Check Code” button not giving any clues or response, I’m not entirely sure what I am missing.

Also, my console is only returning an error in the ‘out of view’ “})” on line 209 and nothing related to my actual code.


SyntaxError: unknown: Unexpected token, expected "," (209:0)

  207 |
  208 |
> 209 | });
            | ^
  210 |

The area I’m working in is Line 202 through 207.

I am lost and have been looking at filter() syntax and implicit return and either my brain is fried and I’m not seeing a simple typo or I’ve missed the concept altogether.
Any help is appreciated. I’ve accepted that researching alone works only so much and I have to be able to ask for help.

yes, or you can use implicit return removing the graph parenthesis

somewhere you have wrong syntax, it could be a missing parenthesis, or a missing comma. You will need to share all your code

Full scope of code 199 - 209


playersDropdownList.addEventListener("change", (e) => {
  playerCards.innerHTML = "";


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


});

you never close switch, it’s probably from there that you have the syntax issue

1 Like

So, switch doesn’t get closed but it was a required bracket to submit the previous step in setting up our switch function.

It’s also present when resetting the page to start the step again.


  switch (e.target.value) {
    case "nickname":

  }

});

However, now that I have reset the page and copied my original code and attempted to submit it, I now have a response from the submit button.

Sorry, your code does not pass. Keep trying.

Your filter() callback should implicitly return the result of checking if player.nickname is not null.


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

  }

Now we can go back to this

1 Like

So, I removed the curly bois and it worked just as you said.

I have noticed in previous steps that using the reset button on page rather than the browser refresh, it makes the submit button work.

I know there was an issue open before on a few steps across a few different JavaScript Beta courses, that the submit button had moments of not responding to incorrect codes. Not sure where exactly to submit that feedback.

Looking back, i see the curly bracket from the switch code was deleted while I was working on it, and that may have been the catalyst to why none of my attempts worked, even when typing return in? Maybe?

a syntax error like that would make the JavaScript crash, yes. Which also makes the button not work

That’s good to know. Sometimes the button not working has me stare at code for an unreasonable amount of time then BOOM! The comma is gone or there’s one too many }. Good to know it’s a formatting issue. That’ll help with reviewing in the future, it actually helped just now to quickly locate the issue on another step.

Thank you so much for having such quick and helpful responses. I’m enjoying the JavaScript Beta courses a lot and the challenge is probably the biggest reason.