-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.js
84 lines (57 loc) · 1.88 KB
/
currency.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
77
78
79
80
81
let date = new Date();
let dd = date.getDate();
if (dd < 10) dd = '0' + dd;
let mm = date.getMonth() + 1;
if (mm < 10) mm = '0' + mm;
let yy = date.getFullYear();
date = yy + mm + dd;
document.querySelector('#statusCurr').insertAdjacentHTML('beforeend',dd + '.' + mm + '.' + yy);
ajax(`https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?date=${date}&json`,'GET',funcResp);
let UAH = {
cc: 'UAH',
rate: 1
}
function funcResp(data){
data = JSON.parse(data.response);
data.push(UAH);
inpNumb.oninput = () =>{
mainFuncCalc(data)
}
selectOut.onchange = () =>{
mainFuncCalc(data)
}
selectInp.onchange = () =>{
mainFuncCalc(data)
}
fillCurr(data);
}
let selectInp = document.querySelector('#inpSelect'),
selectOut = document.querySelector('#outSelect')
inpNumb = document.querySelector('#firstCurrenc'),
outNumb = document.querySelector('#endCurrence');
function mainFuncCalc(obj) {
let enterValue = inpNumb.value;
let selectValueInp = selectInp.value;
let selectValueOut = selectOut.value;
let inpRate, outRate;
for(let i = 0; i < obj.length; i++){
if(selectValueInp == obj[i].cc){
inpRate = obj[i].rate;
}
if(selectValueOut == obj[i].cc){
outRate = obj[i].rate;
}
}
let result = ((inpRate/outRate)*enterValue).toFixed(3);
outNumb.value = result;
}
function fillCurr(arr) {
let cuurFill = document.querySelectorAll('.buy');
for(let j = 0; j <= cuurFill.length-1; j++){
for(let i = 0; i <= arr.length-1; i++){
if(cuurFill[j].name == arr[i].cc){
cuurFill[j].value = (arr[i].rate).toFixed(3);
}
}
}
}