-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise2.js
More file actions
26 lines (23 loc) · 788 Bytes
/
exercise2.js
File metadata and controls
26 lines (23 loc) · 788 Bytes
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
/**
* 1. Install Node fetch if your Node version is less than 18
* 2. Have a read through pokeapi.co
* 3. Make a request to:
* https://pokeapi.co/api/v2/pokemon/pikachu
* and print out pikachu's "official-artwork's URL for their image (png)"
*/
async function fetchPikachuURL() {
const result = []
try {
const response = await fetch('https://pokeapi.co/api/v2/pokemon/pikachu')
if (!response.ok) {
throw new Error(`Response status is ${response.status}`)
}
const data = await response.json()
const {sprites} = data
result.push(sprites.other['official-artwork'])
return result
} catch (error) {
console.error('Error fetching Pikachu', error)
}
}
fetchPikachuURL().then(result => result.map(url => console.log(url.front_default)))