-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathindex.js
More file actions
38 lines (35 loc) · 1.06 KB
/
index.js
File metadata and controls
38 lines (35 loc) · 1.06 KB
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
const API = 'https://rickandmortyapi.com/api/character/';
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
const xhttp = new XMLHttpRequest();
function fetchData(url_api) {
return new Promise((resolve, reject) => {
xhttp.open('GET', url_api, true);
xhttp.send();
xhttp.onreadystatechange = event => {
if (xhttp.readyState === 4) {
if (xhttp.status == 200)
resolve(JSON.parse(xhttp.responseText));
else {
return reject('Se esta presentando un Error');
}
}
};
})
}
Promise.all([fetchData(API)])
.then(data => {
data1=data;
console.log('Primer Llamado...')
return fetchData(`${API}${data1[0].results[0].id}`)
})
.then(data => {
data2=data;
console.log('Segundo Llamado...')
return fetchData(data2.origin.url)
})
.then(data => {
console.log('Tercero Llamado...');
console.log(`Personajes: ${data1[0].info.count}`);
console.log(`Primer Personaje:${data2.name}`);
console.log(`Dimensión: ${data.dimension}`);
})