forked from Flukus99/Rick-and-morty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (34 loc) · 1.11 KB
/
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
const $personajes=document.querySelector(".personajes")
const html=document.implementation.createHTMLDocument();
async function load(){
for (let i = 1; i <=300; i++) {
var personaje20=await llamarPersonaje(i);
var escucha=await escuchar(i)
}
}
async function llamarPersonaje(id){
const data=await fetch("https://rickandmortyapi.com/api/character/".concat(id))
const personaje= await data.json()
const parametro=personaje.image
const nombre=personaje.name
const status=personaje.status
const especie=personaje.species
let template=`<div class="hover" id="${id}">
<img src="${parametro}" alt="">
<div class="informacion">
<p>${nombre}</p>
</div>
</div>`
html.body.innerHTML=template;
$personajes.append(html.body.children[0])
}
load()
function escuchar(id){
var imagen_html=document.getElementById(id);
imagen_html.addEventListener("click",siFunciona);
async function siFunciona(){
const data=await fetch("https://rickandmortyapi.com/api/character/".concat(id));
const data_json= await data.json();
alert(data_json.name)
}
}