Procházet zdrojové kódy

+ change currensy select

ilya_shyian před 3 roky
rodič
revize
2ecd4646c9
1 změnil soubory, kde provedl 20 přidání a 5 odebrání
  1. 20 5
      js/01/index.html

+ 20 - 5
js/01/index.html

@@ -16,18 +16,32 @@
 
         <script>
             let alerts = [];
-            let exchangeRate = {};
+            let exchangeRates = {};
             const _alert = (el) => `
                 <div class="alert ${el.type}">${el.text}</div>
             `;
+
+            const currency = (name, selected) => {
+                return selected
+                    ? `<option value="${name}" selected>${name}</option>`
+                    : `<option value="${name}">${name}</option>`;
+            };
+
+            function updateCurrencyBlock() {
+                let currencyBlock = document.querySelector("#currency");
+                currencyBlock.innerHTML = "";
+                Object.keys(exchangeRates)
+                    .filter((key) => key !== "USD")
+                    .forEach((el) => {
+                        let isSelected = el === "UAH";
+                        currencyBlock.insertAdjacentHTML("beforeend", currency(el, isSelected));
+                    });
+            }
             const exchangeForm = `
             <form action="" class="form" onsubmit="calculate(event)">
                 <div class="form-body">
                     <label for="">Currency:</label>
-                    <select type="number" name="currency" class="form-input">
-                        <option value="RUB">RUB</option>
-                        <option value="UAH">UAH</option>
-                        <option value="EUR">EUR</option>
+                    <select type="number" name="currency" class="form-input" id = "currency">
                     </select>
                     <label for="#amount">Amount</label>
                     <input type="number" name="Amount" id="amount" class="form-input" id="" value="0" />
@@ -71,6 +85,7 @@
                 if (isAuth === true) {
                     document.querySelector("div.header").innerHTML = btnLogout;
                     document.querySelector("div.container-form").innerHTML = exchangeForm;
+                    updateCurrencyBlock();
                     removeAlert("", "error");
                 } else {
                     document.querySelector("div.container-form").innerHTML = authForm;