3/22/25, 2:00 PM script.
js
script.js
1 const apiURL = 'https://api.exchangerate-api.com/v4/latest/';
2
3 async function loadCurrencies() {
4 const res = await fetch(apiURL + 'USD');
5 const data = await res.json();
6 const currencies = Object.keys(data.rates);
7 const fromSelect = document.getElementById('from-currency');
8 const toSelect = document.getElementById('to-currency');
9
10 currencies.forEach(currency => {
11 const option1 = document.createElement('option');
12 option1.value = currency;
13 option1.textContent = currency;
14 fromSelect.appendChild(option1);
15
16 const option2 = option1.cloneNode(true);
17 toSelect.appendChild(option2);
18 });
19
20 fromSelect.value = 'USD';
21 toSelect.value = 'INR';
22 }
23
24 async function convertCurrency() {
25 const amount = document.getElementById('amount').value;
26 const fromCurrency = document.getElementById('from-currency').value;
27 const toCurrency = document.getElementById('to-currency').value;
28
29 if (!amount) return alert('Please enter an amount');
30
31 const res = await fetch(apiURL + fromCurrency);
32 const data = await res.json();
33 const rate = data.rates[toCurrency];
34 const result = (amount * rate).toFixed(2);
35
36 document.getElementById('result').textContent = `${amount} ${fromCurrency} = ${result}
${toCurrency}`;
37 }
38
39 loadCurrencies();
40
localhost:3134/710bd581-9852-4c4f-94fd-da439a19bacb/ 1/1