-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (40 loc) · 1.3 KB
/
app.js
File metadata and controls
43 lines (40 loc) · 1.3 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
var baseUrl = "https://api.coinranking.com/v2/coins";
var proxyUrl = "https://cors-anywhere.herokuapp.com/";
var apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var apiUrl = `${proxyUrl}${baseUrl}`;
console.log(apiUrl);
fetch(`${proxyUrl}${baseUrl}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'X-My-Custom-Header': `${apiKey}`,
'Access-Control-Allow-Origin': "*"
}
})
.then((response) => {
if (response.ok) {
response.json().then((json) => {
console.log(json.data);
let coinsData = json.data.coins;
if (coinsData.length > 0) {
var cryptoCoin = "";
}
//For Loop Starts
coinsData.forEach((coin) => {
cryptoCoin += "<tr>";
cryptoCoin += `<td> ${coin.uuid} </td>`;
cryptoCoin += `<td> ${coin.btcPrice} </td>`;
cryptoCoin += `<td> ${coin.rank}</td>`;
cryptoCoin += `<td> ${coin.tier} </td>`;
cryptoCoin += `<td> ${coin.name}</td>`;
cryptoCoin += `<td> $${Math.round(coin.price)} Billion</td>`;
cryptoCoin += `<td> ${coin.symbol}</td>`;"<tr>";
});
//For Loop Ends
document.getElementById("data").innerHTML = cryptoCoin;
});
}
})
.catch((error) => {
console.log(error);
});