123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- <!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>
|