18 lines
535 B
JavaScript
18 lines
535 B
JavaScript
|
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;
|
||
|
document.getElementById('res').textContent = val*coef + ' ' +document.getElementById('curr2').value;
|
||
|
}
|