-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalAPI.js
48 lines (41 loc) · 1.45 KB
/
globalAPI.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
const trust = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'c599114a1emsh1142a01581c3d5ap1676dfjsndc89f719989b',
'X-RapidAPI-Host': 'coinranking1.p.rapidapi.com'
}
};
fetch('https://coinranking1.p.rapidapi.com/stats?referenceCurrencyUuid=yhjMzLPhuIDl', trust)
.then(response => response.json())
.then((globalInfo) => {
return {
mcap: globalInfo.data.totalMarketCap,
volume: globalInfo.data.total24hVolume,
coins: globalInfo.data.totalCoins,
}
})
.then(globalInfo => added(globalInfo))
const added = (globalInfo) => {
// anchor all elements
const mcaps = document.querySelector('.mCap')
const volumes = document.querySelector('.volume')
const coins = document.querySelector('.coins')
// change number for num with comma
function numberWithCommas(num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
let str = numberWithCommas(globalInfo.mcap)
let volum = numberWithCommas(globalInfo.volume)
//create div for store value
const macap = document.createElement('div');
const vol = document.createElement('div');
const allCoins = document.createElement('div');
// putting data to el.
macap.innerHTML = ('$') + str;
vol.innerHTML = ('$') + volum;
allCoins.innerHTML = globalInfo.coins;
//appending div to anchored el
mcaps.appendChild(macap)
volumes.appendChild(vol)
coins.appendChild(allCoins)
}