diff --git a/main.ts b/main.ts index a54a388..ad6d69c 100644 --- a/main.ts +++ b/main.ts @@ -289,7 +289,7 @@ function head(title: string): string { } (async () => { - const pokemons = await loadPokemons(20); + const pokemons = await loadPokemons(1010); const indexHtml = renderPokemonIndex(pokemons); await writeFile("index.html", indexHtml); diff --git a/pokemon.ts b/pokemon.ts index 784bfc3..dc7a1e8 100644 --- a/pokemon.ts +++ b/pokemon.ts @@ -17,10 +17,12 @@ export class Pokemon { } } - export const loadPokemons = async (n: number) => { + export const loadPokemons = async (n?: number) => { const pokemons: Array = []; - for (let i = 1; i <= n; i++) { + let i = 1; + while (n ? (i <= n) : true) { + const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${i}`); const speciesResponse = await fetch(`https://pokeapi.co/api/v2/pokemon-species/${i}`); @@ -37,7 +39,9 @@ export class Pokemon { pokemons.push(new Pokemon(i, data.species.name, imageUrl, types, is_baby, is_legendary, is_mythical)); } else { console.error(`Error fetching data for Pokémon ID ${i}: ${response.statusText}`); + break; } + i++; } return pokemons; };