-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
61 lines (55 loc) · 1.79 KB
/
script.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
const API_KEY = "72f0872c-959c-424f-8201-3745eb62a6d6";
fetch(
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/map?CMC_PRO_API_KEY=" +
API_KEY
)
.then((response) => {
if (!response.ok)
throw new Error(
"Erro ao executar a requisição, status " + response.status
);
return response.json();
})
.then((api) => {
let texto = `
<div class="container" style="background-color:green;">
<div class="row" style="padding-top: 8px;" >
<div class="col-lg-3" >
<h5 class="mt-2">Nome</h5>
</div>
<div class="col-lg-3"">
<h5 class="mt-2">Símbolo</h5>
</div>
<div class="col-lg-6">
<h5 class="mt-2">Primeiros Dados Históricos em</h5>
</div>
</div>
</div>
`;
for (let contador = 0; contador < 10; contador++) {
const moeda = api.data[contador];
let data = new Date(moeda.first_historical_data);
let dataFormatada =
data.getDate() + "/" + (data.getMonth() + 1) + "/" + data.getFullYear();
const backgroundColor = contador % 2 == 0 ? "white" : "lightgray";
texto =
texto +
`
<div class="container" style="background-color:${backgroundColor};">
<div class="row" style="padding-top: 8px;" >
<div class="col-lg-3" >
<p style="padding-top: 6px;">${moeda.name}</p>
</div>
<div class="col-lg-3"">
<p style="padding-top: 6px;">${moeda.symbol}</p>
</div>
<div class="col-lg-6">
<p style="padding-top: 6px;">${dataFormatada}</ṕ>
</div>
</div>
</div>
`;
}
document.getElementById("coins").innerHTML = texto;
})
.catch((error) => console.error(error.message));