primer commit
This commit is contained in:
commit
5523f3a7c9
36
index.html
Normal file
36
index.html
Normal 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
17
script.js
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user