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

Tell us what’s happening:

everything looks right but it doesn’t work. What should I need to add?

Your code so far

playerCards.innerHTML += arr.map(
({ name, position, number, isCaptain, nickname }) => {
<div class="player-card"> <h2>${name} ${isCaptain} ? "(Captain)" : ""</h2> </div> ;
}
);

WARNING

You should use a ternary operator to check if isCaptain is true and return (Captain) or return an empty string.

Challenge Information:

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

Remember that in JSX (which is what the <div> coding is) the curly brackets take you back into Javascript so you need to make sure you are wrapping the whole of the Javascript code (in this case, the ternary) in curly brackets

doesn’t work with curly brackets

here is my code:

 playerCards.innerHTML += arr.map(
    ({ name, position, number, isCaptain, nickname }) => {
      `
       <div class="player-card">
          <h2>${name} {${isCaptain} ? "(Captain)" : ""} </h2>
        </div>
      `;
    }
  );

Please reply to this message by writing out the Javascript ternary expression you want to use

${isCaptain} ? “(Captain)” : " "

You have used curly brackets here - in Javascript (inside ofJSX) the curly brackets take you back to JSX, and isCaptain is not in JSX, but in Javascript, so you don’t need them here in this Javascript ternary.
Hope that explanation is clear :slight_smile:

Please show me the corrected Javascript ternary

1 Like

Hey Yhan, the question asked to check if isCaptain is true.
First, wrap all your js code in a set of curly brackets, one pair is all you require for this question. Check if isCaptain is strictly true then return “(Captain)” if not, then empty string.

1 Like

solution removed by moderator

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

1 Like