-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (27 loc) · 1016 Bytes
/
index.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
const pokecontainer = document.querySelector('.box');
const search = document.querySelector('.search');
const btn = document.querySelector('.btn');
const URL = 'https://pokeapi.co/api/v2/pokemon/'
btn.addEventListener('click', handleboton);
// input.addEventListener('input', handleText);
async function handleboton(){
try{
const response = await fetch(URL + search.value.toLowerCase())
if (!response.ok){
pokecontainer.classList.add('poke')
pokecontainer.innerHTML = "El pokemon que buscaste no se encontro"
return;
}
pokecontainer.classList.add('poke')
const data = await response.json();
pokecontainer.innerHTML = `
<h1>El pokemon es: ${data.name}</h1>
<img src= '${data.sprites.front_default}'>
<p>Numero: ${data.id}</p>
<p>Altura ${data.height/10} metros</p>
<p>Peso ${data.weight/10} Kg</p>
`
}catch(error){
pokecontainer.innerHTML = "No haz ingresado ningun dato"
}
}