28 lines
740 B
JavaScript
28 lines
740 B
JavaScript
async function api(base){
|
|
const res = await fetch(`https://v6.exchangerate-api.com/v6/aa74a76fa349403ebf36b1ff/latest/${base}`);
|
|
const data = await res.json();
|
|
return data.conversion_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;
|
|
document.getElementById('res').value = Number((val*coef).toFixed(2)).toLocaleString('en');
|
|
}
|
|
|
|
const from1 = document.getElementById('curr');
|
|
const to1 = document.getElementById('curr2');
|
|
|
|
function change(){
|
|
tmp = from1.value;
|
|
from1.value = to1.value;
|
|
to1.value = tmp;
|
|
}
|
|
|