Skip to content

Commit 99f27f7

Browse files
committed
#20 - JavaScript
1 parent b4a5480 commit 99f27f7

File tree

1 file changed

+38
-0
lines changed
  • Roadmap/20 - PETICIONES HTTP/javascript

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const peticion = async () => {
2+
const response = await fetch('https://tronix-portfolio.vercel.app')
3+
if (response.ok) {
4+
const data = await response.text()
5+
console.log(data)
6+
}
7+
}
8+
9+
// peticion()
10+
11+
// DIFICULTAD EXTRA
12+
const obtenerInfoPokemon = async (pokemon) => {
13+
const response = await fetch(`https://pokeapi.co/api/v2/pokemon/${pokemon}`)
14+
if (response.ok) {
15+
const { id, forms: [{ name }], weight, height, types, game_indices } = await response.json()
16+
return {
17+
id, name, height, weight, types, game_indices
18+
}
19+
}
20+
}
21+
22+
const mostrarInformacion = async (pokemon) => {
23+
const response = await obtenerInfoPokemon(pokemon)
24+
const { id, name, weight, height, types, game_indices } = response
25+
const tipos = types.map(type => type.type.name)
26+
const juegos = game_indices.map(juego => juego.version.name)
27+
28+
console.log(`
29+
ID: ${id}
30+
Nombre: ${name}
31+
Altura: ${height}
32+
Peso: ${weight}
33+
Tipo(s): ${tipos}
34+
Juegos: ${juegos}
35+
`)
36+
}
37+
38+
mostrarInformacion(1)

0 commit comments

Comments
 (0)