-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
75 lines (63 loc) · 2.13 KB
/
main.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
//GET Bitcoin Data
function getBitCoinData() {
axios
.get('https://api.coindesk.com/v1/bpi/currentprice.json')
//.then(res => showOutput(res))
.then(res => displayBitcoinData(res))
.catch(err => console.error(err))
}
//Display Bitcoin Price
function displayBitcoinData(res) {
let resData = res.data;
//Get Time
let currentTime = resData["time"]["updated"];
//Get Prices
let currentUSD = resData["bpi"]["USD"]["rate"];
let currentEUR = resData["bpi"]["EUR"]["rate"];
let currentGBP = resData["bpi"]["GBP"]["rate"];
//Get Disclaimer
let disclaimer = resData["disclaimer"];
console.log(resData);
//console.log(res.data);
//console.log(uniqueAlbumIDList);
document.getElementById('dataTable').innerHTML = `
<div class="card mt-3">
<div class="card-header">
Bitcoin Price Information
</div>
<div class="card-body">
<p>Last Refresh: ${currentTime}</p>
<table class="table">
<thead>
<tr>
<th scope="col">Currency</th>
<th scope="col">Bitcoin Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>USD</td>
<td>${currentUSD}</td>
</tr>
<tr>
<td>EUR</td>
<td>${currentEUR}</td>
</tr>
<tr>
<td>GBP</td>
<td>${currentGBP}</td>
</tr>
</tbody>
</table>
<p>${disclaimer}</p>
</div>
</div>
`;
}
//Event listeners
//document.getElementById('get').addEventListener('DOMContentLoaded', getBitCoinData);
document.addEventListener("DOMContentLoaded", function() {getBitCoinData();});
var intervalId = window.setInterval(function(){
getBitCoinData()
console.clear();
}, 300000);