-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
76 lines (61 loc) · 2.39 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
76
$(document).ready(function(){
$.ajax({
url:"https://api.coinmarketcap.com/v1/ticker/?limit=10"
}).done(function(coin){
$.each(coin,function(index,coin){ // for each would
$('#coins').append(`
<div class = "box">
<div class = "upperRow">
<div class = "coin-img">
<img src="img/coin${coin.rank}.png" class="float-left">
</div>
<div class = "price">
<h2>$ ${coin.price_usd}</span></h2>
</div>
<div class = "coin-name">
<h4 class="text-info"></h4><br>${coin.symbol} | ${coin.name}
</div>
<br>
<hr>
<div class = "last-hours">
<div class = "grid-container">
<div class = "item1">
1h : <span id="value1H${coin.rank}"> ${coin.percent_change_1h}</span></span><span class="percentage"> %</span><br>
</div>
<div class = "item2">
24h : <span id="value24H${coin.rank}"> ${coin.percent_change_24h}</span></span><span class="percentage"> %</span><br>
</div>
<div class = "item3">
7d : <span id="value7D${coin.rank}"> ${coin.percent_change_7d}</span></span><span class="percentage"> %</span><br>
</div>
</div> <!-- grid container -->
</div> <!-- last-hours-->
</div> <!-- box -->
`)
});
// Styling based on condition
for (var i = 1; i <= 10; i++) {
// For 1H
if (document.getElementById("value1H"+[i]).innerText < 0) {
document.getElementById("value1H"+[i]).style.color="#ff0000"
}
else if (document.getElementById("value1H"+[i]).innerText > 0) {
document.getElementById('value1H'+[i]).style.color="#220de0"
}
// For 24H
if (document.getElementById("value24H"+[i]).innerText < 0) {
document.getElementById("value24H"+[i]).style.color="#ff0000"
}
else if (document.getElementById("value24H"+[i]).innerText > 0) {
document.getElementById('value24H'+[i]).style.color="#220de0"
}
// For 7D
if (document.getElementById("value7D"+[i]).innerText < 0) {
document.getElementById("value7D"+[i]).style.color="#ff0000"
}
else if (document.getElementById("value7D"+[i]).innerText > 0) {
document.getElementById('value7D'+[i]).style.color="#220de0"
}
}
});
});