commit 5523f3a7c9b057aa5c4d6603af09b4fab35e4ab1 Author: xaloc Date: Sat May 30 13:11:35 2020 +0200 primer commit diff --git a/index.html b/index.html new file mode 100644 index 0000000..1091632 --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + + + + + Conversor + + + + + + + + + +

+Quantitat convertida: +

+ + + + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..2348815 --- /dev/null +++ b/script.js @@ -0,0 +1,17 @@ +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; +}