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

Tell us what’s happening:

When the option All Players is selected, all players should be shown within #player-cards.
14. When the option Position Defender is selected, only defender players should be shown within #player-cards.

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" class="hidden"></option>
        <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: 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;
  }
}
.hidden{
  display:none;
}
/* file: script.js */

const footballTeam={
  team:"Argentina",
  year:1986,
  headCoach:"Carlos Bilardo",
  players:[
 { 
    name:"Sergio Almirón",
    position:"forward",
    isCaptain:false
  },
  {
    name:"Jorge Burruchaga",
    position:"forward",
    isCaptain:false
  },
  {
    name:"José Luis Cuciuffo",
    position:"defender",
    isCaptain:false
  },
  {
    name:"Diego Maradona",
    position:"defender",
    isCaptain:true
  },
  {
    name:"Néstor Clausen",
    position:"goalkeeper",
    isCaptain:false
  },
  {
    name:"Sergio Batista",
    position:"midfielder",
    isCaptain:false
  },
  {
    name:"Daniel Passarella",
    position:"defender",
    isCaptain:false
  },
  {
    name:"Ricardo Bochini",
    position:"midfielder",
    isCaptain:false
  },
  {
    name:"José Luis Brown",
    position:"defender",
    isCaptain:false
  },
  {
    name:"Claudio Borghi",
    position:"midfielder",
    isCaptain:false
  }]
};
const teamName=document.getElementById("team");
const headCoacher=document.getElementById("head-coach");
const yearOfFoundation=document.getElementById("year");
const {team, headCoach, year}= footballTeam;
const playerCards=document.getElementById("player-cards");
const players=document.getElementById("players");

teamName.innerHTML=team;
headCoacher.innerHTML=headCoach;
yearOfFoundation.innerHTML=year;

function getPlayer(position){
  const teamPlayers=footballTeam.players;// arrays in an objecs called players
  playerCards.innerHTML="";// clear previous cards
  const filteredPlayers=position==="all"?teamPlayers:teamPlayers.filter(player=>player.position===position);// assign filtered values to the filteredPlayers- the assigned value is an array.
  filteredPlayers.forEach(player=>creatPlayerCard(player))
}
function creatPlayerCard(player){
  const card=document.createElement("div");
  card.setAttribute("class","player-card");

  card.innerHTML=`<h2>${player.name}</h2>
  <p>${player.position}</p>`;

playerCards.appendChild(card) 
} 

console.log(players.value);

document.addEventListener("DOMContentLoaded", () => {
  getPlayer(players.value);
});
 
players.addEventListener("change",(event)=>{ 
  
  if(event.target.value){
    getPlayer(event.target.value);
  }
}) 

Your browser information:

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

Challenge Information:

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

Hey there,

Please update the message to include your code. The code was too long to be automatically inserted by the help button.

When you enter a code, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Tell us what’s happening:

  1. When the option All Players is selected, all players should be shown within #player-cards.
  2. When the option Position Defender is selected, only defender players should be shown within #player-cards.

Your code so far

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

/* file: styles.css */

/* file: script.js */

Your browser information:

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

Challenge Information:

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

Do you have a question for us? If you need help, you’ll also need to share your code with us. Please edit your post and paste it where indicated between the sets of triple backticks (```).

Please do not make duplicate topics.

Also, please talk to us and tell us how you are stuck fixing your code.

You have not followed the format described in User Story #11.

you are missing the Captain