Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -6,9 +6,6 @@ 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 |
-
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) {
|
|
@@ -30,33 +27,4 @@ document.getElementById('currencyForm').addEventListener('submit', async functio
|
|
| 30 |
} else {
|
| 31 |
// Menyusun nilai konversi dan menampilkannya
|
| 32 |
const rate = data.conversion_rates[toCurrency];
|
| 33 |
-
const convertedAmount = (amount * rate).toFixed
|
| 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'; // IDR menggunakan money-bill-wave
|
| 55 |
-
case 'JPY': return 'yen-sign';
|
| 56 |
-
case 'BRL': return 'money-bill-wave'; // BRL menggunakan 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'; // Ikon default jika tidak ditemukan
|
| 61 |
-
}
|
| 62 |
-
}
|
|
|
|
| 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) {
|
|
|
|
| 27 |
} else {
|
| 28 |
// Menyusun nilai konversi dan menampilkannya
|
| 29 |
const rate = data.conversion_rates[toCurrency];
|
| 30 |
+
const convertedAmount = (amount * rate).toFixed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|