-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (48 loc) · 1.72 KB
/
Copy pathscript.js
File metadata and controls
63 lines (48 loc) · 1.72 KB
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
function FillData() {
let requestURL =
"https://api.privatbank.ua/p24api/pubinfo?json&exchange&coursid=5";
let request = new XMLHttpRequest();
request.open("GET", requestURL);
request.responseType = "json";
request.send();
request.onload = function () {
var currencyRate_json = request.response;
ShowCurrencyRate(currencyRate_json);
};
}
function ShowCurrencyRate(jsonObj) {
let section = document.querySelector("section");
let table = document.createElement("table");
table.classList.add("table", "table-bordered");
let thead = document.createElement("thead");
thead.classList.add("thead-dark");
let tr = document.createElement("tr");
tr.classList.add("text-center");
let headers = ["Currency", "Buy", "Sell"];
headers.forEach(text => {
let th = document.createElement("th");
th.textContent = text;
th.scope = "col";
tr.appendChild(th);
});
thead.appendChild(tr);
table.appendChild(thead);
let tbody = document.createElement("tbody");
jsonObj.forEach(rate => {
let row = document.createElement("tr");
row.classList.add("text-center");
let currencyCell = document.createElement("td");
currencyCell.textContent = `${rate.ccy}/${rate.base_ccy}`;
row.appendChild(currencyCell);
let buyCell = document.createElement("td");
buyCell.textContent = rate.buy;
row.appendChild(buyCell);
let sellCell = document.createElement("td");
sellCell.textContent = rate.sale;
row.appendChild(sellCell);
tbody.appendChild(row);
});
table.appendChild(tbody);
section.appendChild(table);
}
window.onload = FillData;