-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
60 lines (42 loc) · 1.6 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const pokemonContainer = document.querySelector('.pokemon-container');
function fetchPokemon(id) {
fetch(`https://pokeapi.co/api/v2/pokemon/${id}/`)
.then(res => res.json())
.then(data => {
createPokemon(data)
});
}
function fetchPokemons(number) {
for (let i = 1; i <= number; i++) {
fetchPokemon(i);
}
}
function createPokemon(pokemon) {
const card = document.createElement('div');
card.classList.add('pokemon-block');
const spriteContainer = document.createElement('div');
spriteContainer.classList.add('img-container');
const sprite = document.createElement('img');
sprite.src = pokemon.sprites.front_default;
spriteContainer.appendChild(sprite);
const number = document.createElement('p');
number.textContent = `#${pokemon.id.toString().padStart(3, 0)}`
const name = document.createElement('p');
name.classList.add('name');
name.textContent = pokemon.name;
const price = document.createElement('p');
price.classList.add('price');
price.textContent = ('Price: $9.999');
const btnAdd = document.createElement('a');
btnAdd.setAttribute('href',"http://www.index.html");
btnAdd.setAttribute('onclick',function(){alert('Got it!');})
btnAdd.classList.add('btnAdd');
btnAdd.textContent=('Catch!');
card.appendChild(spriteContainer);
card.appendChild(number);
card.appendChild(name);
card.appendChild(price);
card.appendChild(btnAdd);
pokemonContainer.appendChild(card);
}
fetchPokemons(15);