Skip to content

Commit c937581

Browse files
authored
37 pokemon index
1 parent 6ee7742 commit c937581

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

project 37/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<link rel="stylesheet" href="style.css" />
7+
<title>Day 37 Pokedex</title>
8+
</head>
9+
<body>
10+
<h1>Pokedex</h1>
11+
<div class="poke-container" id="poke-container"></div>
12+
13+
<!-- Design inspired by this Dribbble shot: https://dribbble.com/shots/5611109--Pokemon -->
14+
<script src="script.js"></script>
15+
</body>
16+
</html>

project 37/script.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const poke_container = document.getElementById("poke-container");
2+
const pokemon_count = 150;
3+
const colors = {
4+
fire: "#FDDFDF",
5+
grass: "#DEFDE0",
6+
electric: "#FCF7DE",
7+
water: "#DEF3FD",
8+
ground: "#f4e7da",
9+
rock: "#d5d5d4",
10+
fairy: "#fceaff",
11+
poison: "#98d7a5",
12+
bug: "#f8d5a3",
13+
dragon: "#97b3e6",
14+
psychic: "#eaeda1",
15+
flying: "#F5F5F5",
16+
fighting: "#E6E0D4",
17+
normal: "#F5F5F5",
18+
};
19+
20+
const main_types = Object.keys(colors);
21+
22+
const fetchPokemons = async () => {
23+
for (let i = 1; i <= pokemon_count; i++) {
24+
await getPokemon(i);
25+
}
26+
};
27+
28+
const getPokemon = async (id) => {
29+
const url = `https://pokeapi.co/api/v2/pokemon/${id}`;
30+
const res = await fetch(url);
31+
const data = await res.json();
32+
createPokemonCard(data);
33+
};
34+
35+
const createPokemonCard = (pokemon) => {
36+
const pokemonEl = document.createElement("div");
37+
pokemonEl.classList.add("pokemon");
38+
39+
const name = pokemon.name[0].toUpperCase() + pokemon.name.slice(1);
40+
const id = pokemon.id.toString().padStart(3, "0");
41+
42+
const poke_types = pokemon.types.map((type) => type.type.name);
43+
const type = main_types.find((type) => poke_types.indexOf(type) > -1);
44+
const color = colors[type];
45+
46+
pokemonEl.style.backgroundColor = color;
47+
48+
const pokemonInnerHTML = `
49+
<div class="img-container">
50+
<img src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${pokemon.id}.png"" alt="${name}">
51+
</div>
52+
<div class="info">
53+
<span class="number">#${id}</span>
54+
<h3 class="name">${name}</h3>
55+
<small class="type">Type: <span>${type}</span> </small>
56+
</div>
57+
`;
58+
59+
pokemonEl.innerHTML = pokemonInnerHTML;
60+
61+
poke_container.appendChild(pokemonEl);
62+
};
63+
64+
fetchPokemons();

project 37/style.css

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
@import url('https://fonts.googleapis.com/css?family=Lato:300,400&display=swap');
2+
3+
* {
4+
box-sizing: border-box;
5+
}
6+
7+
body {
8+
background: #efefbb;
9+
background: linear-gradient(to right, #d4d3dd, #efefbb);
10+
font-family: 'Lato', sans-serif;
11+
display: flex;
12+
flex-direction: column;
13+
align-items: center;
14+
justify-content: center;
15+
margin: 0;
16+
}
17+
18+
h1 {
19+
letter-spacing: 3px;
20+
}
21+
22+
.poke-container {
23+
display: flex;
24+
flex-wrap: wrap;
25+
align-items: space-between;
26+
justify-content: center;
27+
margin: 0 auto;
28+
max-width: 1200px;
29+
}
30+
31+
.pokemon {
32+
background-color: #eee;
33+
border-radius: 10px;
34+
box-shadow: 0 3px 15px rgba(100, 100, 100, 0.5);
35+
margin: 10px;
36+
padding: 20px;
37+
text-align: center;
38+
}
39+
40+
.pokemon .img-container {
41+
background-color: rgba(255, 255, 255, 0.6);
42+
border-radius: 50%;
43+
width: 120px;
44+
height: 120px;
45+
text-align: center;
46+
}
47+
48+
.pokemon .img-container img {
49+
max-width: 90%;
50+
margin-top: 20px;
51+
}
52+
53+
.pokemon .info {
54+
margin-top: 20px;
55+
}
56+
57+
.pokemon .info .number {
58+
background-color: rgba(0, 0, 0, 0.1);
59+
padding: 5px 10px;
60+
border-radius: 10px;
61+
font-size: 0.8em;
62+
}
63+
64+
.pokemon .info .name {
65+
margin: 15px 0 7px;
66+
letter-spacing: 1px;
67+
}

0 commit comments

Comments
 (0)