Commit 6a5f6db 1 parent 33fd02a commit 6a5f6db Copy full SHA for 6a5f6db
File tree 1 file changed +22
-1
lines changed
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,31 @@ const defense = document.getElementById("defense");
18
18
const specialAttack = document . getElementById ( "special-attack" ) ;
19
19
const specialDefense = document . getElementById ( "special-defense" ) ;
20
20
const speed = document . getElementById ( "speed" ) ;
21
+ // api
22
+ const api = "https://pokeapi.co/api/v2/pokemon/" ;
21
23
22
24
/* Fucntions */
23
25
// returns an abject containing all the required fields.
24
- const getData = async ( ) => { } ;
26
+ const getData = async ( query ) => {
27
+ const res = await fetch ( api + query ) ;
28
+ const data = await res . json ( ) ;
29
+ console . log ( data ) ;
30
+ const pokemon = { } ;
31
+ pokemon . name = data . name ;
32
+ pokemon . id = data . id ;
33
+ pokemon . weight = data . weight ;
34
+ pokemon . height = data . height ;
35
+ pokemon . types = [ ] ;
36
+ data . types . forEach ( ( obj ) => {
37
+ pokemon . types . push ( obj . type . name ) ;
38
+ } ) ;
39
+ data . stats . forEach ( ( obj ) => {
40
+ pokemon [ obj . stat . name ] = obj . base_stat ;
41
+ } ) ;
42
+ // pokemon.sprite = data.sprites.front_default;
43
+ pokemon . sprite = data . sprites . other . showdown . front_default ;
44
+ return pokemon ;
45
+ } ;
25
46
26
47
// updates the DOM with all the values recieved from API
27
48
const update = async ( ) => { } ;
You can’t perform that action at this time.
0 commit comments