-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion6.js
90 lines (77 loc) · 2.09 KB
/
question6.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
const axios = require("axios");
// GET SHIP
async function getShip(id) {
try {
const response = await axios.get(`https://swapi.py4e.com/api/starships/${id}`);
console.log(response.data);
} catch (error) {
console.error(error);
}
}
/* getShip(10); */
// GET PLANET COUNT
async function getPlanetCount() {
try {
const response = await axios.get(`https://swapi.py4e.com/api/planets/`);
console.log(response.data.count);
} catch (error) {
console.error(error);
}
}
/* getPlanetCount(getPlanetCount); */
//SHOW VADER DOB
async function VaderBirth() {
try {
const response = await axios.get(`https://swapi.py4e.com/api/people/?search=Darth%20Vader`);
console.log(response.data.results[0].birth_year);
} catch (error) {
console.error(error);
}
}
/* VaderBirth(); */
//SHOW IN WOOKIEE
async function showInWookiee(id) {
try {
const response = await axios.get(`https://swapi.py4e.com/api/people/${13}?format=wookiee`);
console.log(response.data);
} catch (error) {
console.error(error);
}
}
/* showInWookiee(1); */
//SHOW PLANET
async function showPlanet(url) {
try {
const response = await axios.get(url);
/* console.log(response.data); */
return response.data;
} catch (error) {
console.error(error);
}
}
//SHOW R2-D2 PLANET
async function r2d2Planet() {
try {
const response = await axios.get(`https://swapi.py4e.com/api/people/?search=R2`);
/* console.log(showPlanet(response.data.results[0].homeworld)); */
return showPlanet(response.data.results[0].homeworld);
} catch (error) {
console.error(error);
}
}
/* r2d2Planet(); */
async function showPeopleFromR2d2Planet() {
try {
r2d2Planet().then((response) => {
var residents = response.residents;
console.log(residents);
/* await forEach(residents, async (element) => {
const response = await axios.get(element);
console.log(response);
}); */
});
} catch (error) {
console.error(error);
}
}
showPeopleFromR2d2Planet();