Write a method fetchPokemonData(name)
that fetches data from https://pokeapi.co/api/v2/pokemon/{name}
. The method should simulate network congestion by exponentially increasing the amount of time for each call by doubling it, starting at 200ms.
If the request succeeds, it should resolve with an object containing Pokémon’s name and id, else it should throw an error: Network error occurred.
Write another method searchPokemon(name, timeLimit)
that calls fetchPokemonData(name)
.
The method resolves with the data only if it's received within timeLimit ms.
If the response takes longer than timeLimit
, it should throw an error: Search timed out for
the corresponding Pokemon fetch.
For example: