-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
127 lines (105 loc) · 4.18 KB
/
script.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const fetchPokemon = () => {
const pokeName = document.getElementById("pokeName");
pokeInput = pokeName.value.toLowerCase();
const url = `https://pokeapi.co/api/v2/pokemon/${pokeInput}`;
fetch(url).then((res) => {
if(res.status != "200"){
noData();
} else{
return res.json();
}
}).then((datos) => {
if(datos){
console.log(datos);
let pokeImg = datos.sprites.front_default;
let name = datos.name;
let id = datos.id;
let tipo = datos.types;
let habilidad = datos.abilities;
let estadisticas = datos.stats;
allData(name, id, pokeImg, tipo, habilidad, estadisticas);
}
})
}
const allData = (name, id, url, tipo, habilidad, estadisticas) =>{
nameUpper = name.charAt(0).toUpperCase() + name.slice(1);
document.getElementById("nombre").textContent = `${nameUpper}`;
document.getElementById("id").textContent = `${id}`;
const pokeImg = document.getElementById("pokeImg");
pokeImg.src = url;
let i = 0;
const statName = document.getElementById("type");
statName.innerHTML = "";
for(let D of tipo){
typeUpper = tipo[i].type.name.charAt(0).toUpperCase() + tipo[i].type.name.slice(1);
let addName = document.createTextNode(`${typeUpper} `);
statName.appendChild(addName);
i += 1;
}
i = 0;
const ability = document.getElementById("habilidades");
ability.innerHTML = "";
for(let value of habilidad){
let newListItem = document.createElement('li');
abilityUpper = habilidad[i].ability.name.charAt(0).toUpperCase() + habilidad[i].ability.name.slice(1);
newListItem.textContent = `${abilityUpper}`;
ability.appendChild(newListItem);
i += 1;
}
i = 0;
for(let value of estadisticas){
id1 = `statValue${i}`
if(i == 0){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}else if(i == 1){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}else if(i == 2){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}else if(i == 3){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}else if(i == 4){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}else if(i == 5){
let pNum = document.getElementById(id1);
pNum.textContent = `${estadisticas[i].base_stat}`;
}
i += 1;
}
}
const noData = () =>{
const url = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.XUDg6DfQbTM0uxBDYiGRgQHaGj%26pid%3DApi&f=1";
let pokeImg = document.getElementById("pokeImg");
pokeImg.src = url;
document.getElementById("nombre").textContent = `nel`;
document.getElementById("id").textContent = `nel`;
document.getElementById("habilidades").textContent = `nel`;
document.getElementById("type").textContent = `nel`;
for(let i = 0; i<= 6; i++){
id1 = `statValue${i}`;
if(i == 0){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}else if(i == 1){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}else if(i == 2){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}else if(i == 3){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}else if(i == 4){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}else if(i == 5){
let pNum = document.getElementById(id1);
pNum.textContent = `nel`;
}
}
}
fetchPokemon();