GarGerry commited on
Commit
37ca035
·
verified ·
1 Parent(s): 633af3b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +42 -8
script.js CHANGED
@@ -6,8 +6,10 @@ async function convertCurrency() {
6
  const result = document.getElementById('result');
7
  const convertBtn = document.getElementById('convert-btn');
8
 
 
9
  if (amount && fromCurrency && toCurrency) {
10
  try {
 
11
  const response = await fetch(`https://api.exchangerate-api.com/v4/latest/${fromCurrency}`);
12
  const data = await response.json();
13
  const rate = data.rates[toCurrency];
@@ -51,22 +53,54 @@ document.getElementById('to-currency').addEventListener('change', () => {
51
  document.getElementById('convert-btn').style.display = 'block';
52
  document.getElementById('result').innerHTML = '';
53
  });
54
- // Mengubah warna latar belakang ketika menggulir
 
55
  window.onscroll = function() {
56
  const navbar = document.querySelector('.navbar');
57
- const headline = document.querySelector('.headline');
58
  const steps = document.querySelector('.steps');
59
- const footer = document.querySelector('.footer');
60
 
61
  if (window.scrollY > 200) {
62
  navbar.style.backgroundColor = '#004d00'; // Darker Green
63
- headline.style.backgroundColor = '#004d00'; // Darker Green
64
- steps.style.backgroundColor = '#004d00'; // Darker Green
 
 
65
  footer.style.backgroundColor = '#666666'; // Darker Gray
66
  } else {
67
  navbar.style.backgroundColor = '#006400'; // Original Green
68
- headline.style.backgroundColor = '#006400'; // Original Green
69
- steps.style.backgroundColor = '#006400'; // Original Green
 
 
70
  footer.style.backgroundColor = '#808080'; // Original Gray
71
  }
72
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  const result = document.getElementById('result');
7
  const convertBtn = document.getElementById('convert-btn');
8
 
9
+ // Validasi input
10
  if (amount && fromCurrency && toCurrency) {
11
  try {
12
+ // Mendapatkan data kurs mata uang
13
  const response = await fetch(`https://api.exchangerate-api.com/v4/latest/${fromCurrency}`);
14
  const data = await response.json();
15
  const rate = data.rates[toCurrency];
 
53
  document.getElementById('convert-btn').style.display = 'block';
54
  document.getElementById('result').innerHTML = '';
55
  });
56
+
57
+ // Fungsi untuk menangani scroll dan mengganti warna latar belakang
58
  window.onscroll = function() {
59
  const navbar = document.querySelector('.navbar');
60
+ const howToUse = document.querySelector('.how-to-use');
61
  const steps = document.querySelector('.steps');
62
+ const footer = document.querySelector('footer');
63
 
64
  if (window.scrollY > 200) {
65
  navbar.style.backgroundColor = '#004d00'; // Darker Green
66
+ howToUse.style.backgroundColor = '#004d00'; // Darker Green
67
+ steps.forEach(step => {
68
+ step.style.backgroundColor = '#004d00'; // Darker Green for steps
69
+ });
70
  footer.style.backgroundColor = '#666666'; // Darker Gray
71
  } else {
72
  navbar.style.backgroundColor = '#006400'; // Original Green
73
+ howToUse.style.backgroundColor = '#006400'; // Original Green
74
+ steps.forEach(step => {
75
+ step.style.backgroundColor = '#006400'; // Original Green for steps
76
+ });
77
  footer.style.backgroundColor = '#808080'; // Original Gray
78
  }
79
+ };
80
+
81
+ // Fungsi untuk memuat pilihan mata uang
82
+ function loadCurrencies() {
83
+ const currencies = [
84
+ 'BND', 'KHR', 'IDR', 'LAK', 'MYR', 'MMK', 'PHP', 'SGD', 'THB', 'VND',
85
+ 'EUR', 'GBP', 'CHF', 'RUB', 'TRY', 'USD', 'CAD', 'BRL', 'ARS', 'ZAR',
86
+ 'JPY', 'CNY', 'KRW', 'KPW', 'HKD'
87
+ ];
88
+
89
+ const fromCurrency = document.getElementById('from-currency');
90
+ const toCurrency = document.getElementById('to-currency');
91
+
92
+ currencies.forEach(currency => {
93
+ const optionFrom = document.createElement('option');
94
+ optionFrom.value = currency;
95
+ optionFrom.textContent = `${currency}`;
96
+ fromCurrency.appendChild(optionFrom);
97
+
98
+ const optionTo = document.createElement('option');
99
+ optionTo.value = currency;
100
+ optionTo.textContent = `${currency}`;
101
+ toCurrency.appendChild(optionTo);
102
+ });
103
+ }
104
+
105
+ // Memuat mata uang ketika halaman dimuat
106
+ window.onload = loadCurrencies;