Update script.js
Browse files
script.js
CHANGED
|
@@ -12,7 +12,7 @@ let autoConvert = false;
|
|
| 12 |
convertButton.addEventListener('click', () => {
|
| 13 |
autoConvert = true; // Aktifkan auto-convert
|
| 14 |
convertCurrency(); // Lakukan konversi
|
| 15 |
-
|
| 16 |
});
|
| 17 |
|
| 18 |
// Swap mata uang
|
|
@@ -22,7 +22,7 @@ swapButton.addEventListener('click', () => {
|
|
| 22 |
toCurrency.value = temp;
|
| 23 |
|
| 24 |
if (autoConvert) {
|
| 25 |
-
convertCurrency(); //
|
| 26 |
} else {
|
| 27 |
clearResult(); // Hapus hasil jika auto-convert tidak aktif
|
| 28 |
}
|
|
@@ -37,13 +37,15 @@ swapButton.addEventListener('click', () => {
|
|
| 37 |
});
|
| 38 |
|
| 39 |
element.addEventListener('change', () => {
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
});
|
| 42 |
});
|
| 43 |
|
| 44 |
// Fungsi konversi
|
| 45 |
async function convertCurrency() {
|
| 46 |
-
const amount = amountInput.value;
|
| 47 |
const from = fromCurrency.value;
|
| 48 |
const to = toCurrency.value;
|
| 49 |
|
|
@@ -72,24 +74,7 @@ async function convertCurrency() {
|
|
| 72 |
}
|
| 73 |
}
|
| 74 |
|
| 75 |
-
// Fungsi untuk menyembunyikan tombol Convert
|
| 76 |
-
function hideConvertButton() {
|
| 77 |
-
convertButton.style.display = 'none';
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
// Fungsi untuk menampilkan tombol Convert
|
| 81 |
-
function showConvertButton() {
|
| 82 |
-
convertButton.style.display = 'block';
|
| 83 |
-
}
|
| 84 |
-
|
| 85 |
// Fungsi untuk menghapus hasil konversi
|
| 86 |
function clearResult() {
|
| 87 |
resultDiv.innerHTML = '';
|
| 88 |
}
|
| 89 |
-
|
| 90 |
-
// Fungsi untuk mereset status auto-convert
|
| 91 |
-
function resetAutoConvert() {
|
| 92 |
-
autoConvert = false; // Nonaktifkan auto-convert
|
| 93 |
-
showConvertButton(); // Tampilkan kembali tombol Convert
|
| 94 |
-
clearResult(); // Hapus hasil sebelumnya
|
| 95 |
-
}
|
|
|
|
| 12 |
convertButton.addEventListener('click', () => {
|
| 13 |
autoConvert = true; // Aktifkan auto-convert
|
| 14 |
convertCurrency(); // Lakukan konversi
|
| 15 |
+
convertButton.style.display = 'none'; // Sembunyikan tombol Convert
|
| 16 |
});
|
| 17 |
|
| 18 |
// Swap mata uang
|
|
|
|
| 22 |
toCurrency.value = temp;
|
| 23 |
|
| 24 |
if (autoConvert) {
|
| 25 |
+
convertCurrency(); // Konversi otomatis saat swap
|
| 26 |
} else {
|
| 27 |
clearResult(); // Hapus hasil jika auto-convert tidak aktif
|
| 28 |
}
|
|
|
|
| 37 |
});
|
| 38 |
|
| 39 |
element.addEventListener('change', () => {
|
| 40 |
+
autoConvert = false; // Nonaktifkan auto-convert
|
| 41 |
+
convertButton.style.display = 'block'; // Tampilkan tombol Convert
|
| 42 |
+
clearResult(); // Hapus hasil sebelumnya
|
| 43 |
});
|
| 44 |
});
|
| 45 |
|
| 46 |
// Fungsi konversi
|
| 47 |
async function convertCurrency() {
|
| 48 |
+
const amount = parseFloat(amountInput.value);
|
| 49 |
const from = fromCurrency.value;
|
| 50 |
const to = toCurrency.value;
|
| 51 |
|
|
|
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
// Fungsi untuk menghapus hasil konversi
|
| 78 |
function clearResult() {
|
| 79 |
resultDiv.innerHTML = '';
|
| 80 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|