-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (32 loc) · 1007 Bytes
/
index.js
File metadata and controls
32 lines (32 loc) · 1007 Bytes
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
let api;
let monys = document.querySelectorAll(".monyMun ul li");
let inp = document.querySelectorAll("input");
let inpdiv = document.querySelectorAll(".namMon div");
fetch(
"https://api.currencyfreaks.com/v2.0/rates/latest?apikey=2d99186803994185b445be11c928e68c"
)
.then((e) => {
if (e.status != 200) {
document.querySelector(".titr").innerHTML = "Connection Error";
document.querySelector(".titr").style.color = "red";
}
return e.json();
})
.then((e) => {
api = e;
});
monys.forEach((e) => {
e.addEventListener("click", () => {
inpdiv[1].innerHTML = e.innerHTML;
inp[1].value = transform(e.innerHTML).toFixed(2);
});
});
function transform(mon) {
return api["rates"][mon] * inp[0].value;
}
inp[0].addEventListener("input", () => {
inp[1].value = transform(inpdiv[1].innerHTML).toFixed(2);
});
inp[1].addEventListener("input", () => {
inp[0].value = (inp[1].value / api["rates"][inpdiv[1].innerHTML]).toFixed(2);
});