-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (27 loc) · 857 Bytes
/
script.js
File metadata and controls
29 lines (27 loc) · 857 Bytes
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
const topCoinsContainer = document.querySelector(".top-coins-container");
function createTopCard(item){
const topCardItem = document.createElement("div");
topCardItem.className = "top-card-item";
topCardItem.innerHTML =`<div class="card-logo">
<img src=${item.large} alt="logo">
</div>
<div class="details">
<h2>${item.id}</h2>
<p><span>Rs </span>${item.price_btc * 50000 * 75}</p>
</div>`;
return topCardItem;
}
const fetchTopCardApi = async () => {
try {
const response =await fetch("https://api.coingecko.com/api/v3/search/trending");
const data = await response.json();
data.coins.forEach(element => {
const card = createTopCard(element.item);
console.log(card);
topCoinsContainer.append(card);
});
} catch (error) {
console.log(error);
}
}
fetchTopCardApi();