-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaScript.js
More file actions
46 lines (38 loc) · 1.09 KB
/
javaScript.js
File metadata and controls
46 lines (38 loc) · 1.09 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
const BASE_URL = "https://rickandmortyapi.com/api/character";
const getResult = async () => {
try {
const response = await fetch(BASE_URL);
const data = await response.json();
renderResult(data.results);
} catch (error) {
return error;
}
};
getResult();
const renderResult = (array = []) => {
const container = document.createElement("div");
container.className = "container";
document.body.appendChild(container);
array.map((fortune) => {
const card = document.createElement("div");
card.className = "card";
const img = document.createElement("img");
img.src = fortune.image;
img.alt = fortune.name;
const name = document.createElement("h3");
name.textContent = fortune.name;
const status = fortune.status;
if (status === "Alive") {
card.style.border = "3px solid green";
}
if (status === "Dead") {
card.style.border = "3px solid red";
}
if (status === "unknown") {
card.style.border = "3px solid black";
}
card.appendChild(img);
card.appendChild(name);
container.appendChild(card);
});
};