-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (59 loc) · 1.72 KB
/
index.js
File metadata and controls
65 lines (59 loc) · 1.72 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
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
// const $app = document.querySelector("#app");
// const $div = document.createElement("div");
const getMoreInfo = async (id) => {
try {
const response = await fetch(
`https://fsa-crud-2aa9294fe819.herokuapp.com/api/2505-FTB-CT-WEB-PT/events/${id}`
);
const object = await response.json();
console.log(object.data);
displayOneResults(object.data);
} catch (error) {
console.error(error);
}
};
const displayOneResults = (result) => {
$app = document.querySelector("#app");
$h1 = document.createElement("h1");
$h1.textContent = result.name;
$h2 = document.createElement("h2");
$h2.textContent = result.data;
$app.append($h1);
};
const displayResults = (characters) => {
$app = document.querySelector("#app");
$h1 = document.createElement("h1");
$h1.textContent = "Party Planner";
$app.append($h1);
for (const element of characters) {
$div = document.createElement("div");
$h2 = document.createElement("h2");
//$h2.textContent = element.name;
$button = document.createElement("button");
$button.textContent = element.name;
$button.addEventListener("click", () => getMoreInfo(element.id));
$h3 = document.createElement("h3");
$h3.textContent = "Party Details";
$div.append($h2);
$div.append($h3);
$div.append($button);
$app.append($div);
}
};
const fetchData = async () => {
try {
const response = await fetch(
"https://fsa-crud-2aa9294fe819.herokuapp.com/api/2505-FTB-CT-WEB-PT/events"
);
const data = await response.json();
console.log(data);
displayResults(data.data);
} catch (error) {
console.error(error);
}
};
const start = () => {
console.log("I am in the start function");
fetchData();
};
start();