GennadySht 2 tahun lalu
induk
melakukan
8e57ff7881

+ 0 - 36
js/09/hw09_05_noswitch copy 3.html

@@ -1,36 +0,0 @@
-<head>
-    <h1>noswitch</h1>
-
-</head>
-
-<body>
-    <script>
-        const noSwitch = (key, cases, defaultKey = 'default') =>
-            (cases[key] || cases[defaultKey])();
-        /*{
-            //проверка наличия key в cases
-            const f = cases[key];
-            if (f)
-                return f();
-            else
-                cases[defaultKey]();
-            //если есть - достать значение по ключу. это будет функция. Запустить ее
-            //если нет - извлечь из объекта cases значение по ключу, имя которого лежит в переменной defaultKey. Запустить 
-            //пущай функция noSWitch возвращает то, что возвращает одна из функций из объекта
-        }*/
-        const drink = prompt("Что вы любите пить")
-        noSwitch(drink, {
-            воду: () => console.log('Самый здоровый выбор!'),
-            чай() {
-                console.log('Вкусная и полезная штука. Не переусердствуйте с сахаром')
-            },
-            "пиво": () => console.log('Хорошо летом, да в меру'),
-            виски: function () {
-                console.log('Да вы, батенька, эстет! Не забудьте лед и сигару')
-            },
-            default() {
-                console.log('шото я не понял')
-            }
-        })
-    </script>
-</body>

+ 0 - 36
js/09/hw09_05_noswitch copy.html

@@ -1,36 +0,0 @@
-<head>
-    <h1>noswitch</h1>
-
-</head>
-
-<body>
-    <script>
-        const noSwitch = (key, cases, defaultKey = 'default') =>
-            (cases[key] || cases[defaultKey])();
-        /*{
-            //проверка наличия key в cases
-            const f = cases[key];
-            if (f)
-                return f();
-            else
-                cases[defaultKey]();
-            //если есть - достать значение по ключу. это будет функция. Запустить ее
-            //если нет - извлечь из объекта cases значение по ключу, имя которого лежит в переменной defaultKey. Запустить 
-            //пущай функция noSWitch возвращает то, что возвращает одна из функций из объекта
-        }*/
-        const drink = prompt("Что вы любите пить")
-        noSwitch(drink, {
-            воду: () => console.log('Самый здоровый выбор!'),
-            чай() {
-                console.log('Вкусная и полезная штука. Не переусердствуйте с сахаром')
-            },
-            "пиво": () => console.log('Хорошо летом, да в меру'),
-            виски: function () {
-                console.log('Да вы, батенька, эстет! Не забудьте лед и сигару')
-            },
-            default() {
-                console.log('шото я не понял')
-            }
-        })
-    </script>
-</body>

+ 45 - 0
js/09/hw09_07closure calc 2.html

@@ -0,0 +1,45 @@
+<head>
+    <h1>closure calc 2</h1>
+
+</head>
+
+<body>
+    <select id='from'> </select>
+    <select id='to'></select> <br>
+    <div id='rate'></div><br>
+    <input type='number' id='amount' /><br>
+
+    <div id='result'></div>
+    <script>
+        fetch(`https://open.er-api.com/v6/latest/USD`)
+            .then(response => response.json())
+            .then(data => {
+                let crossRates = {};
+                for (const curr1 in data.rates) {
+                    let option = document.createElement("option");
+                    option.innerText = curr1;
+                    from.append(option);
+                    option = document.createElement("option");
+                    option.innerText = curr1;
+                    to.append(option);
+
+                    let curr1Rates = {};
+                    crossRates[curr1] = curr1Rates;
+                    for (const curr2 in data.rates) {
+                        curr1Rates[curr2] = data.rates[curr2] / data.rates[curr1];
+                    }
+                }
+                const calcResult = () => {
+                    let currFrom = from.value;
+                    let currTo = to.value;
+                    currVal = amount.value;
+                    rateVal = crossRates[currFrom][currTo];
+                    result.innerText = currVal * rateVal;
+                    rate.innerText = rateVal;
+                }
+                from.onchange = calcResult;
+                to.onchange = calcResult;
+                amount.oninput = calcResult;
+            });
+    </script>
+</body>

+ 32 - 0
js/09/hw09_08countries and cities.html

@@ -0,0 +1,32 @@
+<head>
+    <h1>countries and cities</h1>
+
+</head>
+
+<body>
+    <select id='country'> </select><br>
+    <select id='city'></select>
+    <script>
+        fetch('https://raw.githubusercontent.com/russ666/all-countries-and-cities-json/master/countries.min.json').then(res => res.json())
+            .then(data => {
+                for (countryName in data) {
+                    let option = document.createElement("option");
+                    option.innerText = countryName;
+                    country.append(option);
+                }
+
+                const onChangeCountry = () => {
+                    city.innerText = "";
+                    let test = data[country.value];
+                    for (cityName of data[country.value]) {
+                        let option = document.createElement("option");
+                        option.innerText = cityName;
+                        city.append(option);
+                    }
+                }
+                country.onchange = onChangeCountry;
+                onChangeCountry();
+            });
+ 
+    </script>
+</body>