ilya_shyian před 3 roky
rodič
revize
36aedf0f19
2 změnil soubory, kde provedl 361 přidání a 1 odebrání
  1. 1 1
      js/02/index.html
  2. 360 0
      js/03/index.html

+ 1 - 1
js/02/index.html

@@ -288,7 +288,7 @@
 
     //COMPARISON: SIZES
 
-            // let size = prompt("enter size to covert (Russia => USA )")
+            // let size = +prompt("enter size to covert (Russia => USA )")
 
             // if(size>=40 && size <=54){
             //     if(size>= 40 && size<42){

+ 360 - 0
js/03/index.html

@@ -0,0 +1,360 @@
+<!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>
+            //SWITCH: SIZES -----------------------------------------------------------------------
+            function switchSizes() {
+                let size = +prompt("enter size to covert (Russia => USA )");
+
+                switch (size) {
+                    case 40:
+                        alert("S");
+                        break;
+                    case 42:
+                    case 44:
+                        alert("M");
+                        break;
+                    case 46:
+                    case 48:
+                        alert("L");
+                        break;
+                    case 50:
+                    case 52:
+                        alert("XL");
+                        break;
+                    case 54:
+                        alert("XLL");
+                        break;
+                    default:
+                        alert("Incorrect size");
+                }
+            }
+
+            //SWITCH: IF -----------------------------------------------------------------------
+            function switchIF() {
+                let color = prompt("Введите цвет", "");
+
+                if (color == "red") {
+                    document.write("<div style='background-color: red;'>красный</div>");
+                    document.write("<div style='background-color: black; color: white;'>черный</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>");
+                    document.write("<div style='background-color: green;'>зеленый</div>");
+                } else if (color == "green") {
+                    document.write("<div style='background-color: green;'>зеленый</div>");
+                } else {
+                    document.write("<div style='background-color: gray;'>Я не понял</div>");
+                }
+            }
+
+            //PROMPT: OR -----------------------------------------------------------------------
+            function promptOR() {
+                +prompt("How old are you") || alert("error: incorrect age");
+            }
+
+            //CONFIRM: OR THIS DAYS -----------------------------------------------------------------------
+
+            function confirmOR() {
+                confirm("шопинг?") || alert("ты - бяка");
+            }
+
+            //CONFIRM: IF THIS DAYS -----------------------------------------------------------------------
+
+            function confirmIF() {
+                let isShoping = confirm("шопинг?");
+
+                if (isShoping === false) {
+                    alert("ты - бяка");
+                }
+            }
+
+            //TRIPLE PROMPT -----------------------------------------------------------------------
+            function triplePrompt() {
+                let surname = prompt("Фамилия");
+                let name = prompt("Имя");
+                let patronymic = prompt("Отчество");
+
+                alert(` ${surname} ${name} ${patronymic}`);
+            }
+
+            //DEFAULT: OR -----------------------------------------------------------------------
+
+            function defaultOR() {
+                let surname = prompt("Фамилия") || "Иванов";
+                let name = prompt("Имя") || "Иван";
+                let patronymic = prompt("Отчество") || "Иванович";
+                alert(` ${surname} ${name} ${patronymic}`);
+            }
+
+            //DEFAULT: IF -----------------------------------------------------------------------
+
+            function defaultIF() {
+                let surname = prompt("Фамилия") || "Иванов";
+                let name = prompt("Имя") || "Иван";
+                let patronymic = prompt("Отчество") || "Иванович";
+
+                if (!surname) {
+                    surname = "Иванов";
+                }
+                if (!name) {
+                    name = "Иван";
+                }
+                if (!surname) {
+                    patronymic = "Иванович";
+                }
+
+                alert(` ${surname} ${name} ${patronymic}`);
+            }
+
+            //LOGIN AND PASSWORD -----------------------------------------------------------------------
+
+            function loginAndPassword() {
+                while (true) {
+                    let login = prompt("login");
+
+                    if (login && login === "admin") {
+                        let password = prompt("password");
+                        if (password && password === "qwerty") {
+                            alert("successfull login");
+                            break;
+                        } else {
+                            alert("password is incorrect");
+                            continue;
+                        }
+                    } else {
+                        alert("login is incorrect");
+                        continue;
+                    }
+                }
+            }
+
+            //CURRENCY CALC -----------------------------------------------------------------------
+
+            function currencyCalc() {
+                let currency = prompt("Enter currency to convert(usd/eur)");
+                let rate = 1;
+                let amount = +prompt("Amount to convert");
+                switch (currency) {
+                    case "usd":
+                        rate = 26.2;
+                        break;
+                    case "eur":
+                        rate = 30;
+                        break;
+                }
+                if (amount && amount > 0) {
+                    alert(amount / rate).toFixed(3);
+                } else {
+                    alert("error");
+                }
+            }
+
+            //CURRENCY CALC: IMPROVED -----------------------------------------------------------------------
+
+            function currencyCalcImp() {
+                let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
+                let rate = 1;
+                let amount = +prompt("Amount to convert");
+                switch (currency) {
+                    case "usd":
+                        rate = 26.2;
+                        break;
+                    case "eur":
+                        rate = 30;
+                        break;
+                }
+                if (amount && amount > 0) {
+                    alert(amount / rate).toFixed(3);
+                } else {
+                    alert("error");
+                }
+            }
+
+            //CURRENCY CALC: TWO RATES -----------------------------------------------------------------------
+
+            function currencyCalcTwo() {
+                let selling = confirm("Convert on selling rates?");
+                let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
+                let rate = 1;
+                let amount = +prompt("Amount to convert");
+                switch (currency) {
+                    case "usd":
+                        rate = selling ? 26.23 : 26.14;
+                        break;
+                    case "eur":
+                        rate = selling ? 29.99 : 29.83;
+                        break;
+                }
+                if (amount && amount > 0) {
+                    alert(amount / rate).toFixed(3);
+                } else {
+                    alert("error");
+                }
+            }
+
+            //CURRENCY CALC: IF -----------------------------------------------------------------------
+
+            function currencyCalcIF() {
+                let selling = confirm("Convert on selling rates?");
+                let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
+                let rate = 1;
+                let amount = +prompt("Amount to convert");
+
+                if (selling) {
+                    if (currency === "usd") {
+                        rate = 26.23;
+                    }
+                    if (currency === "eur") {
+                        rate = 29.99;
+                    }
+                } else {
+                    if (currency === "usd") {
+                        rate = 26.14;
+                    }
+                    if (currency === "eur") {
+                        rate = 29.83;
+                    }
+                }
+
+                if (amount && amount > 0) {
+                    alert(amount / rate).toFixed(3);
+                } else {
+                    alert("error");
+                }
+            }
+
+            //SCISSORS -----------------------------------------------------------------------
+
+            function scissors() {
+                let chose = prompt("Make ur choise").toLowerCase();
+                let aiChose = "";
+                let random = Math.random();
+
+                if (random <= 0.33) {
+                    aiChose = "камень";
+                } else if (aiChose <= 0.66) {
+                    aiChose = "ножницы";
+                } else {
+                    aiChose = "бумага";
+                }
+
+                console.log(aiChose);
+
+                if (chose === aiChose) {
+                    alert("ничья");
+                } else if (
+                    (chose === "камень" && aiChose === "бумага") ||
+                    (chose === "бумага" && aiChose === "ножницы") ||
+                    (chose === "ножницы" && aiChose === "камень")
+                ) {
+                    alert("You lose");
+                } else {
+                    alert("You win");
+                }
+            }
+
+            //ЗАДАНИЕ НА СИНИЙ ПОЯС -----------------------------------------------------------------------
+            function blue() {
+                let rates = {};
+                let currency = prompt("Enter currency to convert(usd/eur)").toLowerCase();
+                let amount = +prompt("Amount to convert");
+                fetch("https://open.er-api.com/v6/latest/UAH")
+                    .then((res) => res.json())
+                    .then((data) => {
+                        rates["usd"] = data.rates.USD;
+                        rates["eur"] = data.rates.EUR;
+                    })
+                    .then(() => {
+                        if (amount && amount > 0) {
+                            alert((amount * rates[currency]).toFixed(3));
+                        } else {
+                            alert("error");
+                        }
+                    });
+            }
+
+            //ДОПОЛНИТЕЛЬНОЕ ЗАДАНИЕ -----------------------------------------------------------------------
+
+            while (true) {
+                let task = prompt("Enter task name or leave blank to stop", "").toLowerCase();
+                if (task) {
+                    switch (task) {
+                        case "switch: sizes":
+                            switchSizes();
+                            break;
+                        case "switch: if":
+                            switchIF();
+                            break;
+                        case "prompt: or":
+                            promptOR();
+                            break;
+                        case "confirm: or this days":
+                            confirmOR();
+                            break;
+                        case "confirm: if this days":
+                            confirmIF();
+                            break;
+                        case "triple prompt":
+                            triplePrompt();
+                            break;
+                        case "default: if":
+                            defaultIF();
+                            break;
+                        case "default: or":
+                            defaultOR();
+                            break;
+                        case "login and password":
+                            loginAndPassword();
+                            break;
+                        case "currency calc":
+                            currencyCalc();
+                            break;
+                        case "currency calc: improved":
+                            currencyCalcImp();
+                            break;
+                        case "currency calc: two rates":
+                            currencyCalcTwo();
+                            break;
+                        case "currency calc: if":
+                            currencyCalcIF();
+                            break;
+                        case "scissors":
+                            scissors();
+                            break;
+                        case "задание на синий пояс":
+                            blue();
+                            break;
+                        case "задание на черный пояс":
+                            black();
+                            break;
+                    }
+                } else {
+                    break;
+                }
+            }
+
+            //ЗАДАНИЕ НА ЧЕРНЫЙ ПОЯС -----------------------------------------------------------------------
+            function black() {
+                let choise = prompt("Make ur choise").toLowerCase();
+                let random = Math.random();
+                (choise === "камень" && random <= 0.33) ||
+                (choise === "ножницы" && random > 0.33 && random <= 0.66) ||
+                (choise === "бумага" && random > 0.66)
+                    ? alert("ничья")
+                    : (choise === "камень" && random > 0.66) ||
+                      (choise === "ножницы" && random <= 0.33) ||
+                      (choise === "бумага" && random > 0.33 && random <= 0.66)
+                    ? alert("You lose")
+                    : alert("You win");
+            }
+        </script>
+    </body>
+</html>