-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpokemon.js
More file actions
28 lines (21 loc) · 1.01 KB
/
Copy pathpokemon.js
File metadata and controls
28 lines (21 loc) · 1.01 KB
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
const container = document.querySelector('#container'); // Select section by3. ID
const baseUrl = 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/'; // Base URL for Pokémon images
async function loadPokemon() {
for (let i = 1; i <= 151; i++) {
const pokemon = document.createElement('div');
pokemon.classList.add('pokemon');
const label = document.createElement('span');
label.innerText = `#${i}`;
const newImg = document.createElement('img');
newImg.src = `${baseUrl}${i}.png`;
pokemon.appendChild(newImg);
pokemon.appendChild(label);
container.appendChild(pokemon);
// Add a delay of 600ms between requests
await new Promise(resolve => setTimeout(resolve, 600));
}
}
loadPokemon();
// `${baseUrl}${i}.png`: Constructs the image URL as:
// https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png,
// https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/2.png, etc.