hw03_logika_v2.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. let taskList = (`
  2. 1 switch: sizes (размер одежды)
  3. 2 switch: if (цвета)
  4. 3 prompt: or (год рождения)
  5. 4 confirm: or this days (шопинг бяка || &&)
  6. 5 confirm: if this days (шопинг бяка if-else)
  7. 6 triple prompt (ФИО в строку)
  8. 7 default: or (John Doe)
  9. 8 default: if (John Doe with IF)
  10. 9 login and password
  11. 10 currency calc
  12. 11 scissors (камень ножницы бумага) - черный пояс
  13. `)
  14. function hw03_logika_v2() {
  15. var task = +(prompt("Что? Новый хозяин! надо??? Введите номер задания:\n" + taskList, "Напечь за меня пирогов!").toLowerCase());
  16. switch (task) {
  17. case 1: {
  18. alert(`Рука не поднимается переписывать предыдущий код на "switch"`);
  19. let tablOfSize = {
  20. ru: {
  21. countryName: "россия",
  22. size: [40, 42, 44, 46, 48, 50, 52, 54,]
  23. },
  24. eu1: {
  25. countryName: "бельгия германия нидерланды норвегия финляндия швеция",
  26. size: [34, 36, 38, 40, 42, 44, 46, 48,]
  27. },
  28. eu2: {
  29. countryName: "франция швейцария",
  30. size: [36, 38, 40, 42, 44, 46, 48, 50,]
  31. },
  32. italy: {
  33. countryName: "италия",
  34. size: [38, 40, 42, 44, 46, 48, 50, 52,]
  35. },
  36. gb: {
  37. countryName: "великобритания",
  38. size: [8, 10, 12, 14, 16, 18, 20, 22,]
  39. },
  40. usa: {
  41. countryName: "сша",
  42. size: [6, 8, 10, 12, 14, 16, 18, 20,]
  43. },
  44. usa2: {
  45. countryName: "сша",
  46. size: ["S", "M", "", "L", "", "XL", "", "XXL",]
  47. },
  48. }
  49. let inputCountry;
  50. let inputSise;
  51. let targetCountry;
  52. let countOfSize = (-1);
  53. let targetSize = ""
  54. function ucFirst(str) {
  55. if (!str) return str;
  56. if (str === "сша") return "США";
  57. return str[0].toUpperCase() + str.slice(1);
  58. }
  59. while (inputCountry = (prompt("Введите название страны 1:", "Россия")).toLowerCase()) {
  60. inputSise = +(prompt(`Введите размер одежды в этой стране ${inputCountry}:`, "46"));
  61. targetCountry = (prompt("Введите название страны 2:", "Россия")).toLowerCase();
  62. Object.keys(tablOfSize).forEach(function (currentvalue) {
  63. if ((tablOfSize[currentvalue].countryName).includes(inputCountry)) {
  64. countOfSize = tablOfSize[currentvalue].size.indexOf(inputSise)
  65. };
  66. });
  67. Object.keys(tablOfSize).forEach(function (currentvalue) {
  68. if ((tablOfSize[currentvalue].countryName).includes(targetCountry)) {
  69. targetSize += (tablOfSize[currentvalue].size[countOfSize] + ", ")
  70. };
  71. });
  72. inputCountry = ucFirst(inputCountry);
  73. targetCountry = ucFirst(targetCountry);
  74. alert(`${inputCountry} - ${inputSise}\n${targetCountry} - ${targetSize.substring(0, targetSize.length - 2)}`);
  75. targetSize = "";
  76. }
  77. };
  78. break;
  79. case 2: {
  80. // var color = prompt("Введите цвет", "");
  81. // switch (color) {
  82. // case "red": document.write("<div style='background-color: red;'>красный</div>");
  83. // case "black": document.write("<div style='background-color: black; color: white;'>черный</div>");
  84. // break;
  85. // case "blue": document.write("<div style='background-color: blue;'>синий</div>");
  86. // case "green": document.write("<div style='background-color: green;'>зеленый</div>");
  87. // break;
  88. // default: document.write("<div style='background-color: gray;'>Я не понял</div>");
  89. // }
  90. // Перепишите пример выше, используя if-else
  91. let color = "1";
  92. // debugger;
  93. while ((color !== 'stop') && (color)) {
  94. color = prompt("Введите цвет", "");
  95. if ((color === "black") || (color === "red")) {
  96. if (color === "red") { document.write("<div style='background-color: red;'>красный</div>"); }
  97. document.write("<div style='background-color: black; color: white;'>черный</div>");
  98. } else {
  99. if ((color === "blue") || (color === "green")) {
  100. if (color === "blue") { document.write("<div style='background-color: blue;'>синий</div>"); }
  101. document.write("<div style='background-color: green;'>зеленый</div>");
  102. } else { document.write("<div style='background-color: gray;'>Я не понял</div>") }
  103. }
  104. };
  105. };
  106. break;
  107. case 3: {
  108. let age = "";
  109. while (!(age)) {
  110. (age = prompt("Сколько лет вам исполнится (исполнилось) в этом году?")) || (alert("Введите возраст (число)"));
  111. }
  112. alert(`Вы родились в ${new Date().getFullYear() - +age} году, \nконечно, если дата на компьютере установлена правильно.`);
  113. };
  114. break;
  115. case 4: {
  116. ((confirm("Сегодня будет шопинг?")) || (alert("Вот ты бяка!!!"))) && (alert("COOL!!!"));
  117. };
  118. break;
  119. case 5: {
  120. if (confirm("Сегодня будет шопинг?")) { alert("COOL!!!") } else alert("Вот ты бяка!!!");
  121. };
  122. break;
  123. case 6: {
  124. function ucFirst(str) {
  125. if (!str) { return str; }
  126. else {
  127. let strLast = (str.slice(1)).toLowerCase();
  128. return str[0].toUpperCase() + strLast;
  129. }
  130. };
  131. let surname = ucFirst(prompt("Фамилия?", "Иванов"));
  132. let name = ucFirst(prompt("Имя?", "Иван"));
  133. let patronymic = ucFirst(prompt("Отчество", "Иванович"));
  134. alert(surname + " " + name + " " + patronymic);
  135. };
  136. break;
  137. case 7: {
  138. function ucFirst(str) {
  139. if (!str) { return str; }
  140. else {
  141. let strLast = (str.slice(1)).toLowerCase();
  142. return str[0].toUpperCase() + strLast;
  143. }
  144. };
  145. let surname = (prompt("Фамилия?", "Иванов")) || "Doe";
  146. let name = (prompt("Имя?", "Иван")) || "John";
  147. let patronymic = (prompt("Отчество", "Иванович")) || "Ivanovich";
  148. surname = ucFirst(surname);
  149. name = ucFirst(name);
  150. patronymic = ucFirst(patronymic);
  151. alert(surname + " " + name + " " + patronymic);
  152. };
  153. break;
  154. case 8: {
  155. function ucFirst(str) {
  156. if (!str) { return str; }
  157. else {
  158. let strLast = (str.slice(1)).toLowerCase();
  159. return str[0].toUpperCase() + strLast;
  160. }
  161. };
  162. let surname;
  163. let name;
  164. let patronymic;
  165. if (!(surname = (prompt("Фамилия?", "Иванов")))) { surname = "Doe" };
  166. if (!(name = (prompt("Имя?", "Иван")))) { name = "John" };
  167. if (!(patronymic = (prompt("Отчество", "Иванович")))) { patronymic = "Ivanovich" };
  168. surname = ucFirst(surname);
  169. name = ucFirst(name);
  170. patronymic = ucFirst(patronymic);
  171. alert(surname + " " + name + " " + patronymic);
  172. };
  173. break;
  174. case 9: {
  175. // debugger
  176. let correctLogin = "admin";
  177. let correctPass = "qwerty";
  178. let inputLogin = inputPass = "";
  179. if (inputLogin = prompt("Login?")) {
  180. if (inputLogin === correctLogin) {
  181. if (inputPass = prompt("Password"))
  182. if (inputPass === correctPass) { alert("CORRECT") }
  183. else { alert("Incorrect password") }
  184. } else { alert("Incorrect login!") }
  185. };
  186. // Дальше тоже рабочий вариант, но не перестает спрашивать логин, пока не введем правильный логин
  187. // {
  188. // while (!((((inputLogin = prompt("Login?")) && (inputLogin === correctLogin)) || (alert("Такого пользователя не существует.")))
  189. // && ((inputPass = prompt("Password?")) || alert("Пароль надо ввести!"))));
  190. // ((inputLogin === correctLogin) && (inputPass === correctPass)) &&
  191. // !(alert("CORRECT !!")) || (alert("Ваш пароль не верный!"))
  192. // };
  193. };
  194. break;
  195. case 10: {
  196. window.open("./curensy.html", "_self");
  197. };
  198. break;
  199. case 11: {
  200. let greeting = `\nТвой вариант?\n1-камень, 2-ножницы, 3-бумага ?\n\nВведи число:\nДля завершения введи ноль "0"`
  201. let youChoice = "1";
  202. let myChoice;
  203. let arrVariant = ["камень", "ножницы", "бумага"];
  204. let result;
  205. // debugger;
  206. while (!!youChoice) {
  207. while (!(youChoice = +(prompt(greeting, "0"))) && (youChoice !== 0));
  208. if ((youChoice < 4) && (youChoice > 0)) {
  209. myChoice = Math.floor(Math.random() * 3) + 1;
  210. alert(`Мой вариант - ${arrVariant[myChoice - 1]}`);
  211. result = (youChoice - myChoice + 3) % 3;
  212. ((result === 1) && (!alert("Ты проиграл!!! LOSER!"))) ||
  213. (((result === 0) && (!alert("---НИЧЬЯ---"))) ||
  214. (alert("Ты выиграл, мой повелитель!")))
  215. }
  216. }
  217. };
  218. break;
  219. default: { alert("Такого мы еще не умеем...!!!") };
  220. }
  221. }