Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
@@ -6,6 +6,9 @@ document.getElementById('currencyForm').addEventListener('submit', async functio
|
|
6 |
const fromCurrency = document.getElementById('fromCurrency').value;
|
7 |
const toCurrency = document.getElementById('toCurrency').value;
|
8 |
const resultDiv = document.getElementById('result');
|
|
|
|
|
|
|
9 |
|
10 |
// Validasi jumlah yang dimasukkan
|
11 |
if (!amount || amount <= 0) {
|
@@ -28,10 +31,32 @@ document.getElementById('currencyForm').addEventListener('submit', async functio
|
|
28 |
// Menyusun nilai konversi dan menampilkannya
|
29 |
const rate = data.conversion_rates[toCurrency];
|
30 |
const convertedAmount = (amount * rate).toFixed(2);
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
} catch (error) {
|
34 |
resultDiv.innerHTML = "Error fetching conversion rate.";
|
35 |
console.error("Error:", error); // Menampilkan error di konsol
|
36 |
}
|
37 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
const fromCurrency = document.getElementById('fromCurrency').value;
|
7 |
const toCurrency = document.getElementById('toCurrency').value;
|
8 |
const resultDiv = document.getElementById('result');
|
9 |
+
const fromCurrencyIcon = document.getElementById('fromCurrencyIcon');
|
10 |
+
const toCurrencyIcon = document.getElementById('toCurrencyIcon');
|
11 |
+
const conversionResult = document.getElementById('conversionResult');
|
12 |
|
13 |
// Validasi jumlah yang dimasukkan
|
14 |
if (!amount || amount <= 0) {
|
|
|
31 |
// Menyusun nilai konversi dan menampilkannya
|
32 |
const rate = data.conversion_rates[toCurrency];
|
33 |
const convertedAmount = (amount * rate).toFixed(2);
|
34 |
+
|
35 |
+
// Menampilkan hasil konversi
|
36 |
+
conversionResult.innerHTML = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;
|
37 |
+
|
38 |
+
// Menentukan ikon mata uang berdasarkan kode
|
39 |
+
fromCurrencyIcon.className = `fas fa-${getCurrencyIcon(fromCurrency)}`;
|
40 |
+
toCurrencyIcon.className = `fas fa-${getCurrencyIcon(toCurrency)}`;
|
41 |
}
|
42 |
} catch (error) {
|
43 |
resultDiv.innerHTML = "Error fetching conversion rate.";
|
44 |
console.error("Error:", error); // Menampilkan error di konsol
|
45 |
}
|
46 |
+
});
|
47 |
+
|
48 |
+
// Fungsi untuk mendapatkan ikon mata uang berdasarkan kode mata uang
|
49 |
+
function getCurrencyIcon(currency) {
|
50 |
+
switch (currency) {
|
51 |
+
case 'USD': return 'dollar-sign';
|
52 |
+
case 'EUR': return 'euro-sign';
|
53 |
+
case 'GBP': return 'pound-sign';
|
54 |
+
case 'IDR': return 'money-bill-wave';
|
55 |
+
case 'JPY': return 'yen-sign';
|
56 |
+
case 'BRL': return 'money-bill-wave';
|
57 |
+
case 'KRW': return 'won-sign';
|
58 |
+
case 'AUD': return 'dollar-sign';
|
59 |
+
case 'CAD': return 'dollar-sign';
|
60 |
+
default: return 'coins';
|
61 |
+
}
|
62 |
+
}
|