-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
75 lines (72 loc) · 1.52 KB
/
index.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function crytoMoneda(data) {
return `
<tr>
<td>
${data.name}
</td>
<td>
${data.rank}
</td>
<td>
${data.symbol}
</td>
<td>
${data.price_usd}$
</td>
<td>
${data.price_btc}
</td>
<td>
${data.total_supply}$
</td>
<td>
${data.available_supply}$
</td>
<td>
${notNull(data.max_supply)}
</td>
<td>
${data.market_cap_usd}$
</td>
<td ${color(data.percent_change_1h)}>
${data.percent_change_1h}%
</td>
<td ${color(data.percent_change_24h)}>
${data.percent_change_24h}%
</td>
<td ${color(data.percent_change_7d)}>
${data.percent_change_7d}%
</td>
</tr>
`
}
function notNull(n) {
if (n === null) return ''
return n
}
function color(number) {
const result = Number(number)
if (result < 0) {
return `
style='color: red;'
`
} else {
return `
style='color: green;'
`
}
}
const coins = document.getElementById('c')
$('#send').click(() => {
coins.innerHTML = ''
let limit = Number($('#limit').val())
let start = Number($('#start').val())
fetch(`https://api.coinmarketcap.com/v1/ticker/?convert=USD&limit=${limit}&start=${start}`).then((data) => {
console.log(data)
data.json().then((data) => {
data.forEach(c => {
coins.innerHTML += crytoMoneda(c)
})
})
})
})