Update script.js
Browse files
script.js
CHANGED
|
@@ -21,7 +21,7 @@ swapButton.addEventListener('click', async () => {
|
|
| 21 |
fromCurrency.value = toCurrency.value;
|
| 22 |
toCurrency.value = temp;
|
| 23 |
|
| 24 |
-
//
|
| 25 |
if (autoConvert) {
|
| 26 |
convertCurrency();
|
| 27 |
} else {
|
|
@@ -39,7 +39,7 @@ swapButton.addEventListener('click', async () => {
|
|
| 39 |
});
|
| 40 |
|
| 41 |
element.addEventListener('change', () => {
|
| 42 |
-
//
|
| 43 |
autoConvert = false;
|
| 44 |
convertButton.style.display = 'block';
|
| 45 |
resultDiv.innerHTML = '';
|
|
@@ -52,6 +52,7 @@ async function convertCurrency() {
|
|
| 52 |
const from = fromCurrency.value;
|
| 53 |
const to = toCurrency.value;
|
| 54 |
|
|
|
|
| 55 |
if (!amount || amount <= 0) {
|
| 56 |
resultDiv.innerHTML = 'Please enter a valid amount.';
|
| 57 |
return;
|
|
|
|
| 21 |
fromCurrency.value = toCurrency.value;
|
| 22 |
toCurrency.value = temp;
|
| 23 |
|
| 24 |
+
// Lakukan konversi langsung jika autoConvert aktif
|
| 25 |
if (autoConvert) {
|
| 26 |
convertCurrency();
|
| 27 |
} else {
|
|
|
|
| 39 |
});
|
| 40 |
|
| 41 |
element.addEventListener('change', () => {
|
| 42 |
+
// Tampilkan tombol Convert jika ada perubahan manual
|
| 43 |
autoConvert = false;
|
| 44 |
convertButton.style.display = 'block';
|
| 45 |
resultDiv.innerHTML = '';
|
|
|
|
| 52 |
const from = fromCurrency.value;
|
| 53 |
const to = toCurrency.value;
|
| 54 |
|
| 55 |
+
// Validasi input
|
| 56 |
if (!amount || amount <= 0) {
|
| 57 |
resultDiv.innerHTML = 'Please enter a valid amount.';
|
| 58 |
return;
|