2020-05-30 12:11:35 +01:00
|
|
|
async function api(base){
|
|
|
|
const res = await fetch(`https://api.exchangeratesapi.io/latest?base=${base}`);
|
|
|
|
const data = await res.json();
|
|
|
|
return data.rates;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function convert(){
|
|
|
|
const base = document.getElementById('curr').value;
|
|
|
|
const rates = await api(base);
|
|
|
|
const cur = document.getElementById('curr2').value;
|
|
|
|
var coef = rates[cur];
|
|
|
|
if (base==cur){
|
|
|
|
coef = 1;
|
|
|
|
}
|
|
|
|
var val = document.getElementById('val').value;
|
2020-06-18 21:57:25 +01:00
|
|
|
document.getElementById('res').textContent = Number((val*coef).toFixed(2)).toLocaleString('en') + ' ' +document.getElementById('curr2').value;
|
2020-05-30 12:11:35 +01:00
|
|
|
}
|