-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpokedex.js
73 lines (55 loc) · 2.45 KB
/
pokedex.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fetchPokemon = () => {
const pokeNameInput = document.getElementById("pokeName");
let pokeName = pokeNameInput.value;
pokeName = pokeName.toLowerCase();
const url = `https://pokeapi.co/api/v2/pokemon/${pokeName}`;
pokeType.innerHTML = "";
fetch(url).then((res) => {
if (res.status != "200") {
console.log(res);
pokeImage("./pokemon-sad.gif")
}
else {
return res.json();
}
}).then((data) => {
if (data) {
console.log(data);
let pokeImg = data.sprites.other.home.front_default;
pokeImage(pokeImg);
let types = data.types;
let type1 = data.types[0].type.name
if (types.length == 1){
console.log(type1);
types=type1;
document.getElementById("pokeType").innerHTML = `${types}`;
}
else {
let type2 = data.types[1].type.name
console.log(type1,type2);
types=(type1 + " " + type2);
document.getElementById("pokeType").innerHTML = `${types}`;
}
let hp = data.stats[0].base_stat;
let attack = data.stats[1].base_stat;
let defense = data.stats[2].base_stat;
let specialAttack = data.stats[3].base_stat;
let specialDefense = data.stats[4].base_stat;
let speed = data.stats[5].base_stat;
stats = ("HP: " + hp + " " + "ATK: " + attack + " " + "DFS: " + defense + " " + "SPATK: " + specialAttack + " " + "SPDFS: " + specialDefense + " " + "SP: " + speed);
console.log(hp, attack, defense,specialAttack, specialDefense,speed);
document.getElementById("stats").innerHTML=`${stats}`;
let moves = data.moves;
for (let i = 0; i < moves.length; i++){
pokemoves=moves[i].move.name;
const moveList = document.createElement("li");
moveList.innerText = `${pokemoves}`;
document.getElementById("pokeMoves").appendChild(moveList);
}
}
})
}
const pokeImage = (url) => {
const pokePhoto = document.getElementById("pokeImg");
pokePhoto.src = url;
}