|
@@ -0,0 +1,121 @@
|
|
|
+// currency calc
|
|
|
+// Калькулятор обмена валют.Первый prompt спрашивает валюту: "usd" или "eur".
|
|
|
+// С помощью switch установите обменный курс для валюты, выбранной пользователем,
|
|
|
+// после чего спросите величину и переведите её из гривны в выбранную на первом prompt валюту.
|
|
|
+// Выведите результат в alert()
|
|
|
+
|
|
|
+// currency calc: improved
|
|
|
+// Улучшить предыдущее задание: сделать возможность ввода валюты любыми буквами(usd, uSd, USD),
|
|
|
+// используйте str.toLowerCase().
|
|
|
+
|
|
|
+// currency calc: two rates
|
|
|
+// Добавить к возможность выбора обменного курса на продажу и покупку.Используйте confirm для ввода
|
|
|
+// пользователя и тернарный оператор для величины курса.
|
|
|
+
|
|
|
+// currency calc: if
|
|
|
+// Сделать тоже самое на if
|
|
|
+const f10 = (rootId) => {
|
|
|
+ const task10block = document.createElement('div');
|
|
|
+ const task10_1title = document.createElement('h2');
|
|
|
+ task10_1title.innerText = 'Task-10-1 Сurrency calc + Task-10-2 Сurrency calc: improved';
|
|
|
+
|
|
|
+ const task10_3title = document.createElement('h2');
|
|
|
+ task10_3title.innerText = 'Task-10-3 Сurrency calc: two rates';
|
|
|
+ const task10_4title = document.createElement('h2');
|
|
|
+ task10_4title.innerText = 'Task-10-4 Сurrency calc calc: if';
|
|
|
+
|
|
|
+ const exchange_01Btn = document.createElement('button');
|
|
|
+ exchange_01Btn.innerText = "Exchange UAH to USD or EUR";
|
|
|
+ exchange_01Btn.style = 'margin-bottom:20px';
|
|
|
+
|
|
|
+ const exchange_03Btn = document.createElement('button');
|
|
|
+ exchange_03Btn.innerText = "Exchange UAH to USD or EUR";
|
|
|
+ exchange_03Btn.style = 'margin-bottom:20px';
|
|
|
+
|
|
|
+ const exchange_04Btn = document.createElement('button');
|
|
|
+ exchange_04Btn.innerText = "Exchange UAH to USD or EUR";
|
|
|
+ exchange_04Btn.style = 'margin-bottom:20px';
|
|
|
+
|
|
|
+ rootId.appendChild(task10block);
|
|
|
+ task10block.appendChild(task10_1title);
|
|
|
+ task10block.appendChild(exchange_01Btn);
|
|
|
+ exchange_01Btn.onclick = () => {
|
|
|
+ const toCurrency = prompt('Введите валюту, которую хотите купить: EUR или USD');
|
|
|
+ let fromAmount = null;
|
|
|
+ let toAmount;
|
|
|
+ switch (toCurrency.toLowerCase()) {
|
|
|
+ case 'usd':
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / 27.62;
|
|
|
+ break;
|
|
|
+ case 'eur':
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / 31.06;
|
|
|
+ break;
|
|
|
+ default: alert('Чет я не понял, попробуйте еще раз');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ !fromAmount || alert(`На ${fromAmount} UAH вы можете приобрести ${Math.round(toAmount * 100) / 100} ${toCurrency.toUpperCase()} `);
|
|
|
+ }
|
|
|
+
|
|
|
+ task10block.appendChild(task10_3title);
|
|
|
+ task10block.appendChild(exchange_03Btn);
|
|
|
+ exchange_03Btn.onclick = () => {
|
|
|
+ const toCurrency = prompt('Введите валюту, которую хотите купить: EUR или USD');
|
|
|
+ let fromAmount = null;
|
|
|
+ let toAmount;
|
|
|
+ let chosenCourse;
|
|
|
+ if (toCurrency) {
|
|
|
+ switch (toCurrency.toLowerCase()) {
|
|
|
+ case 'usd':
|
|
|
+ confirm('Использовать курс продажи 27.62? Если нет, то будет использован курс покупки 27.15') ? (chosenCourse = 27.62) : (chosenCourse = 27.15);
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / chosenCourse;
|
|
|
+ break;
|
|
|
+ case 'eur':
|
|
|
+ confirm('Использовать курс продажи 31.06? Если нет, то будет использован курс покупки 30.55') ? (chosenCourse = 31.06) : (chosenCourse = 30.55);
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / chosenCourse;
|
|
|
+ break;
|
|
|
+ default: alert('Чет я не понял, попробуйте еще раз');
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ ((!fromAmount && alert('Чет я не понял, попробуйте еще раз') || !fromAmount)) || alert(`На ${fromAmount} UAH вы можете приобрести ${Math.round(toAmount * 100) / 100} ${toCurrency.toUpperCase()} `);
|
|
|
+ }
|
|
|
+ else { alert('Чет я не понял, попробуйте еще раз') };
|
|
|
+ }
|
|
|
+
|
|
|
+ task10block.appendChild(task10_4title);
|
|
|
+ task10block.appendChild(exchange_04Btn);
|
|
|
+ exchange_04Btn.onclick = () => {
|
|
|
+ const toCurrency = prompt('Введите валюту, которую хотите купить: EUR или USD');
|
|
|
+ let fromAmount = null;
|
|
|
+ let toAmount = null;
|
|
|
+ let chosenCourse;
|
|
|
+ if (toCurrency) {
|
|
|
+ if (toCurrency.toLowerCase() === 'usd') {
|
|
|
+ confirm('Использовать курс продажи 27.62? Если нет, то будет использован курс покупки 27.15') ? (chosenCourse = 27.62) : (chosenCourse = 27.15);
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / chosenCourse;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if (toCurrency.toLowerCase() === 'eur') {
|
|
|
+ confirm('Использовать курс продажи 31.06? Если нет, то будет использован курс покупки 30.55') ? (chosenCourse = 31.06) : (chosenCourse = 30.55);
|
|
|
+ fromAmount = prompt('Введите сумму в гривне');
|
|
|
+ toAmount = fromAmount / chosenCourse;
|
|
|
+ }
|
|
|
+ else { alert('Чет я не понял, попробуйте еще раз'); }
|
|
|
+ }
|
|
|
+
|
|
|
+ //Проверка на неккоректный ввод:
|
|
|
+ toAmount || ((!fromAmount && alert('Чет я не понял, попробуйте еще раз') || !fromAmount)) || alert(`На ${fromAmount} UAH вы можете приобрести ${Math.round(toAmount * 100) / 100} ${toCurrency.toUpperCase()} `);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ else { alert('Чет я не понял, попробуйте еще раз') };
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+ f10(root);
|
|
|
+export default f10;
|
|
|
+
|