Build a Set of Football Team Cards - Build a Set of Football Team Cards

Tell us what’s happening:

Hey everyone, can´t seem to get step 11 and step 13 correct. Which is wierd because technically they are working in the preview.

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>
      Build a Set of Football Team Cards
    </title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <h1 class="title">Team stats</h1>
    <main>
      <div class="team-stats">
        <p>Team: <span id="team"></span></p>
        <p>Year: <span id="year"></span></p>
        <p>Head coach: <span id="head-coach"></span></p>
      </div>
      <label class="options-label" for="players">Filter Teammates:</label>
      <select name="players" id="players">
        <option value="all">All Players</option>
        <option value="forward">Position Forward</option>
        <option value="midfielder">Position Midfielder</option>
        <option value="defender">Position Defender</option>
        <option value="goalkeeper">Position Goalkeeper</option>
      </select>
      <div class="cards" id="player-cards">
        
      </div>
    </main>
    <footer>&copy; freeCodeCamp</footer>
    <script src="./script.js"></script>
  </body>
</html>

/* file: script.js */
const footballTeam = {
  team: "Manchester United",
  year: 2024,
  headCoach: "Erik ten Hag",
  players: [
    { name: "Bruno Fernandes", position: "midfielder", isCaptain: true },
    { name: "Marcus Rashford", position: "forward", isCaptain: false },
    { name: "Raphaël Varane", position: "defender", isCaptain: false },
    { name: "Andre Onana", position: "goalkeeper", isCaptain: false }
  ]
};

document.getElementById("team").textContent = footballTeam.team;
document.getElementById("year").textContent = footballTeam.year;
document.getElementById("head-coach").textContent = footballTeam.headCoach;

const container = document.getElementById("player-cards");
const playerCards = [];

footballTeam.players.forEach(item => {
  const card = document.createElement("div");
  card.className = "player-card";

  const title = document.createElement("h2");
  if (item.isCaptain) {
    title.textContent = `Captain - ${item.name}`;
  } else {
    title.textContent = item.name;
  }
  card.appendChild(title);

  const position = document.createElement("p");
  position.textContent = item.position;
  card.appendChild(position);

  playerCards.push({ card, position: item.position });
  container.appendChild(card);
});

const select = document.getElementById("players");

select.addEventListener("change", () => {
  const selectedPosition = select.value;


container.innerHTML = "";
  
if (selectedPosition === "all") {
  playerCards.forEach(({ card }) => {
    container.appendChild(card);
  });
} else {
  playerCards.forEach(({ card, position }) => {
    if (selectedPosition === position) {
      container.appendChild(card);
    }
  });
}

});









/* file: styles.css */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --dark-grey: #0a0a23;
  --light-grey: #f5f6f7;
  --white: #ffffff;
  --black: #000;
}

body {
  background-color: var(--dark-grey);
  text-align: center;
  padding: 10px;
}

.title,
.options-label,
.team-stats,
footer {
  color: var(--white);
}

.title {
  margin: 1.3rem 0;
}

.team-stats {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  font-size: 1.3rem;
  margin: 1.2rem 0;
}

.options-label {
  font-size: 1.2rem;
}

.cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.player-card {
  background-color: var(--light-grey);
  padding: 1.3rem;
  margin: 1.2rem;
  width: 300px;
  border-radius: 15px;
}

@media (max-width: 768px) {
  .team-stats {
    flex-direction: column;
  }
}

Your browser information:

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

Challenge Information:

Build a Set of Football Team Cards - Build a Set of Football Team Cards

I wonder if having the cards exist, even if not added to the page, is making so that the tests see them

1 Like

and nested in it, an h2 containing the name of the player, and (Captain) in case of the player being captain

Take a look at this instruction again…looks like you may have overlooked something there.

I missed that! you are right

the test would not recognise the name because of the missing () and the extra dash

2 Likes