Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -8,25 +8,18 @@ async function convertCurrency() {
|
|
| 8 |
|
| 9 |
if (amount && fromCurrency && toCurrency) {
|
| 10 |
try {
|
| 11 |
-
|
| 12 |
-
const response = await fetch(`https://v6.exchangerate-api.com/v6/3ebe2ccf9eeea2aaef280201/latest/${fromCurrency}`);
|
| 13 |
const data = await response.json();
|
| 14 |
-
|
| 15 |
-
if (data.result === 'error') {
|
| 16 |
-
throw new Error('Error fetching exchange rates!');
|
| 17 |
-
}
|
| 18 |
-
|
| 19 |
const rate = data.rates[toCurrency];
|
| 20 |
const convertedAmount = (amount * rate).toFixed(2);
|
| 21 |
|
| 22 |
// Menampilkan hasil konversi
|
| 23 |
result.innerHTML = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;
|
| 24 |
|
| 25 |
-
//
|
| 26 |
convertBtn.style.display = 'none';
|
| 27 |
} catch (error) {
|
| 28 |
result.innerText = "Error fetching exchange rates!";
|
| 29 |
-
console.error('Error fetching exchange rates:', error);
|
| 30 |
}
|
| 31 |
}
|
| 32 |
}
|
|
@@ -57,4 +50,27 @@ document.getElementById('from-currency').addEventListener('change', () => {
|
|
| 57 |
document.getElementById('to-currency').addEventListener('change', () => {
|
| 58 |
document.getElementById('convert-btn').style.display = 'block';
|
| 59 |
document.getElementById('result').innerHTML = '';
|
| 60 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
if (amount && fromCurrency && toCurrency) {
|
| 10 |
try {
|
| 11 |
+
const response = await fetch(`https://v6.exchangerate-api.com/v6/YOUR_API_KEY/latest/${fromCurrency}`);
|
|
|
|
| 12 |
const data = await response.json();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
const rate = data.rates[toCurrency];
|
| 14 |
const convertedAmount = (amount * rate).toFixed(2);
|
| 15 |
|
| 16 |
// Menampilkan hasil konversi
|
| 17 |
result.innerHTML = `${amount} ${fromCurrency} = ${convertedAmount} ${toCurrency}`;
|
| 18 |
|
| 19 |
+
// Sembunyikan tombol Convert setelah konversi otomatis
|
| 20 |
convertBtn.style.display = 'none';
|
| 21 |
} catch (error) {
|
| 22 |
result.innerText = "Error fetching exchange rates!";
|
|
|
|
| 23 |
}
|
| 24 |
}
|
| 25 |
}
|
|
|
|
| 50 |
document.getElementById('to-currency').addEventListener('change', () => {
|
| 51 |
document.getElementById('convert-btn').style.display = 'block';
|
| 52 |
document.getElementById('result').innerHTML = '';
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
// Mengubah warna latar belakang ketika menggulir
|
| 56 |
+
window.onscroll = function() {
|
| 57 |
+
const navbar = document.querySelector('.navbar');
|
| 58 |
+
const headline = document.querySelector('.headline');
|
| 59 |
+
const steps = document.querySelector('.steps');
|
| 60 |
+
const footer = document.querySelector('.footer');
|
| 61 |
+
|
| 62 |
+
if (window.scrollY > 200) {
|
| 63 |
+
navbar.style.backgroundColor = '#004d00'; // Darker Green
|
| 64 |
+
headline.style.backgroundColor = '#004d00'; // Darker Green
|
| 65 |
+
steps.style.backgroundColor = '#004d00'; // Darker Green
|
| 66 |
+
footer.style.backgroundColor = '#666666'; // Darker Gray
|
| 67 |
+
} else {
|
| 68 |
+
navbar.style.backgroundColor = '#006400'; // Original Green
|
| 69 |
+
headline.style.backgroundColor = '#006400'; // Original Green
|
| 70 |
+
steps.style.backgroundColor = '#006400'; // Original Green
|
| 71 |
+
footer.style.backgroundColor = '#808080'; // Original Gray
|
| 72 |
+
}
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
// Fungsi untuk menampilkan hasil swap mata uang secara otomatis setelah pemilihan
|
| 76 |
+
document.getElementById('swap-btn').addEventListener('click', swapCurrencies);
|