Browse Source

HW<3> done

Andrey 2 years ago
parent
commit
37317e43b0
1 changed files with 289 additions and 0 deletions
  1. 289 0
      Dz3 js/Dz3js.html

+ 289 - 0
Dz3 js/Dz3js.html

@@ -0,0 +1,289 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+
+<body>
+    <script>
+        let taskName = prompt ("Введите название задания:")
+        switch(taskName){
+            case "switch: sizes":
+                let country = prompt("Выбирете страну на выбор: Италия, Швейцария")
+                let size = prompt("Введите размер верхней одежды: от 46 - до 50.")
+                switch (country) {
+
+                    case "Италия":
+
+                        switch (size) {
+                            case "46":
+                                alert("44")
+                                break;
+                            case "47":
+                                alert("45");
+                                break;
+                            case "48":
+                                alert("46");
+                                break;
+                            case "49":
+                                alert("47");
+                                break;
+                            case "50":
+                                alert("48");
+                                break;
+                            default:
+                                alert("Вы ввели не правильный размер")
+                        }
+                        break;
+
+                    case "Швейцария":
+
+                        switch (size) {
+                            case "46":
+                                alert("42");
+                                break;
+                            case "47":
+                                alert("43");
+                                break;
+                            case "48":
+                                alert("44");
+                                break;
+                            case "49":
+                                alert("45");
+                                break;
+                            case "50":
+                                alert("46");
+                                break;
+                            default:
+                                alert("Вы ввели не правильный размер");
+                        }
+                        break;
+
+                    default:
+                        alert("УПС!!!")
+
+
+                }
+            
+        case "switch: if":
+        let color = prompt("Введите цвет", "");
+        if (color == "red") {
+            document.write("<div style='background-color: red;'>красный</div>")
+        }
+        else if (color == "black") {
+            document.write("<div style='background-color: black; color: white;'>черный</div>");
+        }
+        else if (color == "blue") {
+            document.write("<div style='background-color: blue;'>синий</div>");
+        }
+        else if (color == "green") {
+            document.write("<div style='background-color: green;'>зеленый</div>");
+        }
+
+        else {
+            document.write("<div style='background-color: gray;'>Я не понял</div>")
+        }
+
+        case "Number: age":
+        let year = 2022;
+        let birthday;
+        let age = +prompt("Сколько вам лет?")
+        if (age) {
+            birthday = year - age;
+            alert(birthday + " г.р.");
+        }
+        else if ((age == null) || (age == "")) {
+                alert("Ошибка!")
+        }else {
+            alert("NO_NO!")
+        }
+
+
+
+        case "confirm: or this days":
+        let shopping = confirm("Шопинг?")
+        alert(shopping || "Ты бяка!")
+
+        case "confirm: if this days":
+        let shopping2 = confirm("Шопинг?")
+        if (shopping2) {
+            alert("Люблю покупки!")
+        }else if((shopping2 == null) || (shopping2 == "")){
+            alert("Ты бяка!")
+        }
+
+
+
+
+        case "triple prompt":
+        let userSurname = prompt("Введите вашу фамилию:")
+        let userName = prompt("Введите ваше имя:") 
+        let userPatronymic = prompt("Введите ваше отчество:") 
+        let fullName = userSurname + ' ' + userName + ' ' +  userPatronymic;
+        alert(fullName)
+
+        case "default: or":
+        let userSurname2 = prompt("Введите вашу фамилию:") || ("Иванов" )
+        let userName2 = prompt("Введите ваше имя:") || ("Иван")
+        let userPatronymic2 = prompt("Введите ваше отчество:") || ("Иваночив")
+        let fullName2 = userSurname2 + ' ' + userName2 + ' ' +  userPatronymic2;
+        alert(fullName)
+
+        case "default: if":
+        
+        let userName3 = prompt("Введите ваше имя");
+            let userSurname3 = prompt("Введите вашу фамилию");
+            let userPatronymic3 = prompt("Введите ваше отчество");
+            if (userName3 == null || "") {
+                userName3 = "Иван";
+            }
+            if (userSurname3 == null || "") {
+                userSurname3 = "Иванов";
+            }
+            if (userPatronymic3 == null || "") {
+                userPatronymic3 = "Иванович";
+            }
+
+            alert(userSurname3 + " " + userName3 + " " + userPatronymic3);
+        
+
+
+        case "login and password":
+        let login = prompt("Введите ваш логин:");
+        if(login === "admin"){
+            let password = prompt("Введите ваш пароль:");
+            if (password === "qwerty"){
+                alert("Поздравляю!");
+            }else if(password === "" || password === null) {
+                alert("Охрана-Отмена!");
+            }else {
+                alert("Неверный пароль!!!")
+            }
+        }else if (login === "" || login === null){
+            alert("Не тут то было!")
+        }else{
+            alert("Вы кто такой? Я вас не звал! Идите за русским кораблем!")
+        }
+
+        case "currency calc":
+        // case "currency calc: improved":
+        // //case "currency calc: two rates":
+        let currency = prompt("Выбирете валюту: usd или eur ").toLowerCase();
+        let UAH = prompt("Введите сумму в гривнах: ");
+        let usdPurchase = 29.2;
+        let usdSale = 29.5;
+        let eurPurchase = 31.4;
+        let eurSale = 32.2;
+        switch (currency) {
+
+            case "usd":  let userExchangeUsd = confirm("Выберите покупка или проадажа? ок-покупка  отмена-продажа") ? (UAH / usdPurchase) : (UAH / usdSale)
+            alert(userExchangeUsd)
+            break;
+
+            case "eur": let userExchangeEur = confirm("Выберите покупка или проадажа? ок-покупка  отмена-продажа") ? (UAH / eurPurchase) : (UAH / eurSale)
+            alert(userExchangeEur)
+            break;
+
+            default: alert("Простите мы закрыты!")
+
+
+        }
+        case "currency calc: if":
+        let currency = prompt("Выбирете валюту: usd или eur ").toLowerCase();
+        let UAH = prompt("Введите сумму в гривнах: ");
+        let usdPurchase = 29.2;
+        let usdSale = 29.5;
+        let eurPurchase = 31.4;
+        let eurSale = 32.2;
+        if (currency === "usd") {
+            let userExchangeUsd = confirm("Выберите покупка или проадажа? ок-покупка  отмена-продажа") ? (UAH / usdPurchase) : (UAH / usdSale)
+            alert(userExchangeUsd)
+        }
+        else if (currency === "eur") {
+            let userExchangeEur = confirm("Выберите покупка или проадажа? ок-покупка  отмена-продажа") ? (UAH / eurPurchase) : (UAH / eurSale)
+            alert(userExchangeEur)
+        }
+        else {
+            alert("Простите мы закрыты!")
+        }
+
+        case "scissors":
+        let userChoice = Number(prompt("Выбирите число от 1 до 3. 1 - камень 2 - ножницы, 3 - бумага"))
+        let compRandom = Math.ceil(Math.random() * 3)
+        alert(`Противник выбрал: ${compRandom} `)
+        if (userChoice === 1 && compRandom === 2 || userChoice === 2 && compRandom === 3 || userChoice === 3 && compRandom === 1) {
+            alert("Ура!!!Вы победили!")
+        }
+        else if (userChoice === 3 && compRandom === 2 || userChoice=== 2 && compRandom === 1 || userChoice === 1 && compRandom === 3) {
+            alert("ОЙ-ОЙ!Вы проиграли!")
+        } else {
+            alert("Победила дружба!!!")
+        }
+
+        case "Задание на синий пояс":
+        let currencySelection = prompt("Выбери одну валюту на выбор: usd или eur").toLowerCase();
+        let enterAmount = prompt ("Введите сумму в гривнах")
+        let ratios = {
+            usd: 25.6,
+            eur: 29
+        }
+        if (currencySelection === "usd"){
+            alert(enterAmount / ratios["usd"])
+        } else if (currencySelection === "eur"){
+            alert(enterAmount / ratios["eur"])
+        }else {
+            alert("Вы ввели не верные данные!")
+        }
+
+        case "real data":
+        let currencySelection2 = prompt("Выбери одну валюту на выбор: usd или eur").toLowerCase();
+        let enterAmount2 = prompt ("Введите сумму в гривнах");       
+        if(currencySelection2 === "usd"){
+            fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
+            .then(data => {
+                alert(data.rates.UAH)
+            })}
+        else if (currencySelection2 === "eur"){
+            fetch('https://open.er-api.com/v6/latest/EUR').then(res => res.json())
+            .then(data => {
+                alert(data.rates.UAH)
+            })}
+        else {
+            alert("Что-то пошло не так!")
+        }
+    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+    </script>
+
+</body>
+
+</html>