Skip to content

Commit ff7c8aa

Browse files
committed
#20 - TypeScript, JavaScript, Python
1 parent 0409435 commit ff7c8aa

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const baseURL = 'https://pokeapi.co/api/v2/pokemon'
2+
3+
const getData = async (number) => {
4+
try{
5+
const res = await fetch(`${baseURL}/${number}`)
6+
const data = await res.json()
7+
8+
console.log('Name: ', data.name)
9+
console.log('ID: ', data.id)
10+
console.log('Weight: ', data.weight)
11+
console.log('Height: ', data.height)
12+
13+
const types = data.types.map(type => type.type.name)
14+
console.log('Types: ', types)
15+
16+
const games = data.game_indices.map(game => game.version.name)
17+
console.log('Games: ', games)
18+
}catch(error){
19+
console.log(error)
20+
}
21+
}
22+
23+
getData(9)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import requests
2+
3+
baseURL = 'https://pokeapi.co/api/v2/pokemon'
4+
5+
def getData(number):
6+
url = baseURL + '/' + number
7+
res = requests.get(url)
8+
data = res.json()
9+
print('Name: ', data['name'])
10+
print('ID: ', data['id'])
11+
print('Weight: ', data['weight'])
12+
print('Height: ', data['height'])
13+
14+
types = [type_info['type']['name'] for type_info in data['types']]
15+
print('Types:', types)
16+
17+
games = [game['version']['name'] for game in data['game_indices']]
18+
print('Games:', games)
19+
20+
21+
getData('9')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const baseURL: string = 'https://pokeapi.co/api/v2/pokemon'
2+
3+
const getData = async (number: number) => {
4+
try{
5+
const res = await fetch(`${baseURL}/${number}`)
6+
const data = await res.json()
7+
8+
console.log('Name: ', data.name)
9+
console.log('ID: ', data.id)
10+
console.log('Weight: ', data.weight)
11+
console.log('Height: ', data.height)
12+
13+
const types: Array<string> = data.types.map(type => type.type.name)
14+
console.log('Types: ', types)
15+
16+
const games: Array<string> = data.game_indices.map(game => game.version.name)
17+
console.log('Games: ', games)
18+
}catch(error){
19+
console.log(error)
20+
}
21+
}
22+
23+
getData(9)

0 commit comments

Comments
 (0)