primer commit

This commit is contained in:
Xaloc 2020-05-30 13:11:35 +02:00
commit 5523f3a7c9
2 changed files with 53 additions and 0 deletions

36
index.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang='fr'>
<head>
<meta charset="UTF-8">
<meta name="author" content="Arnau Busom i Vidal">
<title>Conversor</title>
</head>
<body>
<select id='curr'>
<option value='EUR'>EUR</option>
<option value='USD'>USD</option>
<option value='SEK'>SEK</option>
<option value='JPY'>JPY</option>
<option value='GBP'>GBP</option>
</select>
<input type='number' id='val' step='0.01'>
<select id='curr2'>
<option value='USD'>USD</option>
<option value='EUR'>EUR</option>
<option value='SEK'>SEK</option>
<option value='JPY'>JPY</option>
<option value='GBP'>GBP</option>
</select>
<p>
Quantitat convertida: <span id='res'></span>
</p>
<button onClick='convert()'>convertir</button>
<script src='script.js'></script>
</body>
</html>

17
script.js Normal file
View File

@ -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;
}